前段时间我做了一个REGEX模式,我不记得它的含义了。对我来说,这是一种只写语言:)
这是REGEX:
"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$"
我需要用简单的英语知道这意味着什么。
答案 0 :(得分:5)
(?!^[0-9]*$)
不匹配数字,
(?!^[a-zA-Z]*$)
不匹配字母,
^([a-zA-Z0-9]{8,10})$
匹配字母和数字长度为8到10个字符。
答案 1 :(得分:4)
零宽度负前瞻断言。例如,
/foo(?!bar)/
匹配任何未出现'bar'的'foo'。但请注意,前瞻和后瞻不是一回事。你不能用它来做后卫。
这意味着,
(?!^[0-9]*$)
表示:不匹配,如果字符串包含仅数字。(^
:行/字符串的开头,$
:结束行/字符串)另一个相应的。
您的正则表达式匹配任何字符串,其中包含两个数字和字母,但不仅包含其中一个字符串。
干杯,
更新:对于将来的RegExp定制,请查看(?#...)
模式。它允许您在正则表达式中嵌入注释。还有一个修饰符,re.X
,但我不太喜欢这个。这是你的选择。
答案 2 :(得分:2)
RegexBuddy说以下(!?!):
(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$
Options: ^ and $ match at line breaks
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!^[0-9]*$)»
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match a single character in the range between “0” and “9” «[0-9]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Assert position at the end of a line (at the end of the string or before a line break character) «$»
Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!^[a-zA-Z]*$)»
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match a single character present in the list below «[a-zA-Z]*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
A character in the range between “a” and “z” «a-z»
A character in the range between “A” and “Z” «A-Z»
Assert position at the end of a line (at the end of the string or before a line break character) «$»
Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
Match the regular expression below and capture its match into backreference number 1 «([a-zA-Z0-9]{8,10})»
Match a single character present in the list below «[a-zA-Z0-9]{8,10}»
Between 8 and 10 times, as many times as possible, giving back as needed (greedy) «{8,10}»
A character in the range between “a” and “z” «a-z»
A character in the range between “A” and “Z” «A-Z»
A character in the range between “0” and “9” «0-9»
Assert position at the end of a line (at the end of the string or before a line break character) «$»
答案 3 :(得分:1)
使用类似expresso的内容进行分析。