I coded using python to match the following condition re pattern that identifies the language over the alphabet {a, b} of all strings in which each 'b' is preceded by at least one 'a'
import re
s = '''
a
aaaa
ab
aba
abaabaaaab
b
abb
bba
'''
regex = re.finditer(r"^([aA]+[bB]?)+", s, re.M)
for i in regex:
print(i.group())
I'm getting 'ab' at output from 'abb' on 7th line of multi line string. But it should not happen. I don't want it in output. What change must be done in regular expression to rectify this error.