The above regular expression (in Java) matches a string of alpha numeric characters of length between 5 and 10.
上面的正则表达式(在Java中)匹配长度在5到10之间的字符串。
How can I modify the above regular expression to match with the above requirements as well as matching with an empty string?
如何修改上面的正则表达式以与上面的要求匹配,以及如何与空字符串匹配?
2 个解决方案
#1
16
Make it optional (match exactly one or zero times)
可选(精确匹配1或0次)
^([a-zA-Z0-9]{5,10})?$
#2
4
^(?:[a-zA-Z0-9]{5,10}|)$
^(?:[a-zA-Z0-9]{ 5 10 } |)美元
#1
16
Make it optional (match exactly one or zero times)
可选(精确匹配1或0次)
^([a-zA-Z0-9]{5,10})?$
#2
4
^(?:[a-zA-Z0-9]{5,10}|)$
^(?:[a-zA-Z0-9]{ 5 10 } |)美元