Regular Expressions

Eddie Corns eddie at holyrood.ed.ac.uk
Mon Mar 29 08:50:15 EST 2004


<achaljalan at yahoo.com> writes:

>--0-1311302120-1080428097=:61125
>Content-Type: text/plain; charset=us-ascii

>Hey,

>I have a string
>        s =740446505        "O'HANLON, Benjamin"
>i need to use one RE to convert it into 
>  
>       (740446505, "O'HANLN", "Benjamin"),

What you need to tell us is what the input *pattern* is eg

     s =NNNNNNNNN            "Surname, Forename"

what are the rules? are those quotes always there? can you guarantee a single
comma? (ie no initials), do you always strip the second O from the Surname? :)

It actually looks suspiciously like a fixed format string which would be much
easier to break up using string slicing and string routines like split(',')
and find('"') etc.

Have we had the following quote on c.l.p recently: 

    Some people, when confronted with a problem, think "I know, I'll use
    regular expressions." Now they have two problems. 
	 
	--Jamie Zawinski, in comp.lang.emacs 	 

Seeing this the first time did actually make me realise I was probably using
REs too often.

Eddie



More information about the Python-list mailing list