python - Regex - match if the number of occurences of x is the same as y -


this question has answer here:

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

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -