I am trying to match "any consecutive chains of SAME character that is NOT .(period) "
Lets say I have
line = '....xooo......'
If I do this,
match in re.findall(r'[^\.]{2,}', line)
match returns "xooo".
Instead, I only want "ooo," which is a sequence of SAME character..
How do I do this?
line = '....xooo......aaaa...'
import re
print [whole for whole, _ in re.findall("(([^.])\\2+)", line)]
Output
['ooo', 'aaaa']
([^.])
matches anything but .
and it is captured as a group. \\2
refers to the inner captured group which is the character matched by ([^.])
and +
means atleast once. So, it matches ooo
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句