Regex match even number of letters

python, regex

Solution

Try this regular expression:

^[^A]*((AA)+[^A]*)*$

And if the `A`s don’t need to be consecutive:

^[^A]*(A[^A]*A[^A]*)*$

Problem

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 # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match ``` An even number of As SHOULD match.

Original source