extracting a substring

Dale Strickland-Clark dale at riverhall.nospam.co.uk
Tue Apr 18 20:57:58 EDT 2006


You don't need a regex for this, as long as the prefix and suffix are fixed
lengths, the following will do:

>> "a53bc_531.txt"[6:-4]
'531'
>>> "a53bc_2285.txt"[6:-4]
'2285'



b83503104 at yahoo.com wrote:

> Hi,
> I have a bunch of strings like
> a53bc_531.txt
> a53bc_2285.txt
> ...
> a53bc_359.txt
> 
> and I want to extract the numbers 531, 2285, ...,359.
> 
> One thing for sure is that these numbers are the ONLY part that is
> changing; all the other characters are always fixed.
> 
> I know I should use regular expressions, but I'm not familar with
> python, so any quick help would help, such as which commands or idioms
> to use.  Thanks a lot!

-- 
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk




More information about the Python-list mailing list