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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -