parsing combination strings

Tommy Nordgren tommy.nordgren at comhem.se
Wed Mar 21 14:55:46 EDT 2007


On 21 mar 2007, at 19.42, PKKR wrote:

> I need a fast and efficient way to parse a combination string(digits +
> chars)
>
> ex: s = "12ABA" or "1ACD" or "123CSD" etc
>
> I want to parse the the above string such that i can grab only the
> first digits and ignore the rest of the chacters,
>
> so if i have s = "12ABA" , parser(s) should give me "12" or "1" or
> "123".
>
> I can think of a quick dirty way by checking each element in the
> string and do a 'str.isdigit()' and stop once its not a digit, but
> appreciate any eligent way.
	You need to look up regular expressions in the Documentation.
A regular expression that matches only at the start of the string is  
appropriate
for this problem.

------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
tommy.nordgren at comhem.se





More information about the Python-list mailing list