regex - How to extract data from formatted string using python? -
i have set of strings this:
c001f01.png
c001g01.png
c002f10.png
which follow format of :
c(id number)(f or g)(another id number).png
i want know ids' , know if class f or g, have read re.split()
similar work, i'm confused , don't understand how re works exactly.
you should read more on regex. first hint when want capture pattern need enclose in parentheses. e.g. (\d+). example though, code need is:
match = re.match(r'c(\d+)([f|g])(\d+)\.png', s) first_id = match.group(1) fg_class = match.group(2) second_id = match.group(3)
Comments
Post a Comment