字母数字正则表达式模式匹配
我需要一个匹配字母数字模式(完全数字模式除外)的正则表达式。
asdfgesod valid 1asdndwdd valid asd124asd valid a2asd43bd valid 123346678 invalid
I need a regex that matches the alphanumeric patterns except totally numeric ones.
asdfgesod valid 1asdndwdd valid asd124asd valid a2asd43bd valid 123346678 invalid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
分解:
^[a-z0-9]*
- 字符串以任意数量(包括零)的字母数字字符开头[az]
- 字符串有一个az
字符[a-z0-9]*$
- 字符串以任意数量(包括零)的字母数字字符结尾Broken down:
^[a-z0-9]*
- String starts with any number (including zero) of alphanumeric characters[a-z]
- String has ana-z
character[a-z0-9]*$
- String ends with any number (including zero) of alphanumeric characters您可以尝试:
查看
[a-z0-9]+$
确保该字符串仅由字母数字字符组成。负向先行
(?![0-9]+$)
确保字符串不全是数字。You can try:
See it
[a-z0-9]+$
ensures the string is made of only alphanumeric characters.The negative lookahead
(?![0-9]+$)
ensures the string is not all numeric.解决方案是首先检查字符串是否仅包含数字,如果不包含,则检查字符串的其余部分。以下正则表达式可以做到这一点:
在此处查看其实际情况:http://regexr.com?2v8n5
A solution would be to first check if the string contains only digits, if not check rest of the string. The following regex would do that:
See it in action here: http://regexr.com?2v8n5
在 java
StringUtils.isNumeric(String value)
的情况下使用检查字符串是否仅包含数字。顺便说一句:如果字符串与正则表达式匹配:
"^\d*$"
这意味着它只包含数字。Use in case of java
StringUtils.isNumeric(String value)
check if string contains only numbers.BTW: if string matches regex:
"^\d*$"
this means that it contains only digits.