Python 解释这个特殊的正则表达式

Python 解释这个特殊的正则表达式,python,regex,Python,Regex,不久前我做了一个正则表达式模式,我不记得它的意思了。对我来说,这是一种只写的语言: 以下是正则表达式: "(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$" 我需要知道,用简单的英语,它意味着什么 (?!^[0-9]*$) 不要只匹配数字 (?!^[a-zA-Z]*$) 不要只匹配字母 ^([a-zA-Z0-9]{8,10})$ 匹配字母和8到10个字符长。如下所示!?: (?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA

不久前我做了一个正则表达式模式,我不记得它的意思了。对我来说,这是一种只写的语言:

以下是正则表达式:

"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$"
我需要知道,用简单的英语,它意味着什么

(?!^[0-9]*$)
不要只匹配数字

(?!^[a-zA-Z]*$)
不要只匹配字母

^([a-zA-Z0-9]{8,10})$
匹配字母和8到10个字符长。

如下所示!?:

(?!^[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) «$»  
并据此对…说?!。。。第部分:

零宽度负前瞻断言。例如/foo?!bar/匹配任何不后跟“bar”的“foo”。但是请注意,向前看和向后看不是一回事。您不能将此项用于查找

也就是说

(?!^[0-9]*$)
表示:如果字符串仅包含数字,则不匹配。^:行/字符串的开头,$:行/字符串的结尾对应另一行

您的regexp匹配任何包含数字和字母的字符串,但不只是其中一个

干杯


更新:对于您未来的RegExp裁剪,请查看?。。。图案它允许您在regexp中嵌入注释。还有一个修饰符re.X,但我不太喜欢这个。这是你的选择。

如果你不能阅读正则表达式,就不应该编写它们。如果你从未学习过正则表达式,并且突然要维护包含正则表达式的代码,那么这是一个合理的问题。这应该有什么帮助呢-好问题,在应用程序中看起来更有用!谢谢你给我介绍RegexBuddy。