Reputation: 377
My strings can be:
string = 'thumbC_L_001_JOIN'
string = 'L_thumbC_001_JOIN'
match = re.match(r'^(?:\b\w|_){}(?:\b\w|_)+'.format('L'), chain,flags=re.IGNORECASE)
print(match)
I need to find the letter L in this case wherever it be between two underscores or at the beginning of the string with an underscore after it
Upvotes: 0
Views: 557
Reputation: 163632
Maybe you could use lookaheads with an alternation to assert that the letter L is at the start of the string followed by an underscore or that the letter L is surrounded by an underscore:
^L(?=_)
Match L and assert that what follows is an underscore|
Or(?<=_)L(?=_)
Assert that what is on the left is an underscore, match L
and assert that what follows is an underscoreUpvotes: 1