import re
re.match('^(?=b*(?:ab*ab*)*ab*$)(?=a*(?:ba*ba*)*ba*$)', 'ab')
re.match('^(?=b*(?:ab*ab*)*ab*$)(?=a*(?:ba*ba*)*ba*$)', 'aab')
Can we use regular expressions to check if there are an odd number of each type of character?