regex - Python regular expression search vs match -
i'm trying utilize python regular look match 'brahuihan' or 'brahuiyourba'
>> re.search(r'((brahui|han|yoruba)+\d+)', '10xbrahuihan50_10xbrahuiyoruba50n4').groups() ('brahuihan50', 'han') this returns 1 group, first one, thought should homecoming sec 1 too. i.e brahuiyoruba
if want capture occurrences of pattern, need utilize re.findall:
>>> import re >>> re.findall(r'((brahui|han|yoruba)+\d+)', '10xbrahuihan50_10xbrahuiyoruba50n4') [('brahuihan50', 'han'), ('brahuiyoruba50', 'yoruba')] >>> re.search capture first occurrence.
python regex
No comments:
Post a Comment