I have the following Python regex pattern from an earlier question:
regex_pat = re.compile('''
(
[a-zA-Z\*]*
\*
[a-zA-Z\*]*
)+
''', re.VERBOSE)
Now I want the match to fail if any digit is mixed in with the "word", especially at the start or the end.
text = '''
(A) Match these:
*** star* st**r
(B) Not these:
800*m *4,500
(C) And not these:
800**m **4,000
'''
By trying a pair of negative lookahead and negative lookbehind in various places, I can get rid of the (B) matches, but not the (C) matches. For example:
regex_pat = re.compile('''
(
[a-zA-Z\*]*
(?<!\d)
\*
(?!\d)
[a-zA-Z\*]*
)+
''', re.VERBOSE)
regex_pat.findall(text)
# ['***', 'star*', 'st*r', '**m', '**'] The last two matches are no good.
Apparently, when regex runs into a negative lookahead, it takes a step back to see if it can get a match. How can I make the negative lookarounds greedier or more destructive, so to speak?