python - Regex - match if the number of occurences of x is the same as y -
this question has answer here:
- regular expression equal number of 0 , 1 4 answers
i try make regex matches if times x appears in string equal time y appears
for example: "..x..y..y.x.." should match example: "..x..y..y.x..x" should not match
it's part of more complex regex, can't using count function of python.
thanks help
you can use re.findall:
import re s = "..x..y..y.x.." if len(re.findall("x", s)) == len(re.findall("y", s)): pass
Comments
Post a Comment