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

Popular posts from this blog

android - IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling -

go - serving up pdfs using golang -

how to add preprocess loader in webpack 2 -