I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:
AAA # no match AA
Why work so hard coming up with a hard to read pattern? Just search for all occurrences of the pattern and count how many you find.
len(re.findall("A", "AbcAbcAbcA")) % 2 == 0
That should be instantly understandable by all experienced programmers, whereas a pattern like "(?
Simple is better.
A* means match "A" zero or more times.
For an even number of "A", try: (AA)+