Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要以下符号的任意组合的正则表达式(Regex.Match)
a-z A-Z 0-9 ()[]_-.
长度为 2 到 16 个符号。例子:
asdqwe23)) asd[-_]QWE 0(.)qwe[zz_-].
我试过这个
^[\w\d\r\n\d\[\]\(\)-_]{2,16}
但它不起作用,它允许 !@#$%^&* 符号在除第一个以外的任何地方。超过 17 个长度的字符串也返回 isSucsess true。
使用这个正则表达式^[_a-zA-Z\d\[\]\(\)\-\.]{2,16}$
^[_a-zA-Z\d\[\]\(\)\-\.]{2,16}$
利用
var input = "asd[-_]QWE"; var result = Regex.Matches(input, @"^[A-Za-z0-9\(\)\[\]_\-\.]{2,16}$"); Console.WriteLine(result[0]);