[英]regular expression to match a dot before group with re.findall
When I want to match a dot as literal in a string, it works when the escaped dot is followed by a literal, but not when it's followed by a re group. 当我想将点匹配为字符串中的文字时,在转义的点后跟文字时可以使用它,但是在重新组合时不能使用。
>>> re.findall(r'\.de', 'abc.de')
['.de']
But with a group the dot is lost 但是随着一群人的消失
>>> re.findall(r'\.(de|ab)', 'abc.de')
['de']
How can I re.findall ['.de']
with a group in my regular expression? 如何在正则表达式中用一个组重新搜索['.de']
?
You are capturing the wrong group :-) 您正在捕获错误的组:-)
re.findall(r'(\.(?:de|ab))', 'abc.de')
#or
# re.findall(r'\.(?:de|ab)', 'abc.de')
I have ignored your original group using ?:
我忽略了使用?:
的原始组?:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.