Reputation: 1432
I have this str list
l=['Cu_3', 'P_2', 'O_8']
and this two regexp
import re
sub = re.compile('_([0-9])')
sub2 = re.compile('._([0-9])')
sub doesn't match any elemetn of the list, while sub2 matches the last two but not the first one.. I am probably missing something but I expected to capture the numbers after the underscore with both of them. What's the problem here?
Upvotes: 0
Views: 54
Reputation: 798706
The problem is that you're using the match()
method instead of the search()
method, so your regexs are anchored at the start of the string.
Upvotes: 4