You can use this regex with 2 backlinks to match alternating lowercase letters:
^([az])(?!\1)([az])(?:\1\2)*\1?$
RegEx Demo
RegEx Distribution:
^ : Start([az]) : match the first letter in capture group # 1(?!\1) : Lookahead to make sure we don't repeat the same letter.([az]) : match the second letter in capture group # 3(?:\1\2)* : match zero or more pairs of the first and second letters\1? : Match the optional first letter to the end$ : End
source share