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.
我想要一个正则表达式来测试满足以下要求的字符串:
a-z
A-Z
0-9
-
_
它应该匹配以下字符串:
有人可以帮我吗?提前致谢!
你有你的作品,所以把它们放在一起:
/^[a-z0-9](?:[a-z0-9_ -]*[a-z0-9])?$/i
这正是您正在寻找的。唯一复杂的部分是允许单个字符。