[英]Multiple repeat in re.compile
I am trying some regexes in python but i keep on getting this error 我正在尝试使用python中的一些正则表达式,但我不断收到此错误
Multiple repeat
import re
z = "\\w\\w(?:\\w+\\.)*+"
re.compile(z)
How can i resolve this error? 我该如何解决该错误?
You are using a possessive quantifier *+
and don think you really need it. 您正在使用所有格量词
*+
并且认为您确实需要它。
Try changing your regex to: 尝试将您的正则表达式更改为:
\\w\\w(?:\\w+\\.)*
Update: as Casimir et Hippolyte commented in your question, your problem is on the possessive quantifier: 更新:正如卡西米尔(Casimir)和希波吕特(Hippolyte )在您的问题中所说,您的问题在于所有格量词:
The re module doesn't support possessive quantifiers +.
re模块不支持所有格量词+。 If you really need them (that is not the case with your pattern), use the regex module instead (pypi.python.org/pypi/regex).
如果您确实需要它们(模式不是这种情况),请改用regex模块(pypi.python.org/pypi/regex)。 Note: if you don't want to use double backslashes everywhere, use raw strings: r'\\w\\w(?:\\w+.) '
注意:如果您不想在任何地方都使用双反斜杠,请使用原始字符串:r'\\ w \\ w(?:\\ w +。) '
您的正则表达式中不能同时包含*
和+
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.