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.
如何编写可以包含“AZ”和“az”以及“-”和“ _”字符的正则表达式:
_
从评论:
Regex.IsMatch(userName, @"[-a-zA-Z_]+\d*");
^[a-z0-9-_]*[a-z]+[a-z0-9-_]*$带有i不区分大小写的标志
^[a-z0-9-_]*[a-z]+[a-z0-9-_]*$
i
或者^[a-zA-Z0-9-_]*[a-zA-Z]+[a-zA-Z0-9-_]*$
^[a-zA-Z0-9-_]*[a-zA-Z]+[a-zA-Z0-9-_]*$
或者
-_- [fails, because it's missing a-z or A-Z] 123 [fails, because it's missing a-z or A-Z] ABC [OK] A_1 [OK] _A1 [OK] 1_A [OK]