How to Re this string!
eddie at holyrood.ed.ac.uk
Tue Aug 13 15:41:07 CEST 2002
sjoshi at ingr.com (Sunit Joshi) writes:
>I have string like(apce at end)
>20 1 18 40 'p14h105' 'MCHE Drains and Vents' 'p14h105.dgn'
>'g:\pdstest\models\piping\' 'sunitw2k' 0 0
>for which I'm trying to write an re exp. The intgers are separated by
>a space and the strings enclosed in "'". I need to write out the final
>string delimited by a ";"
>Could someone please help mw with an Re.exp for this.
You need to be a bit more careful about explaining exactly what you want but
my guess is that you want to convert from whitespace delimited to ';'
delimited. So something like:
x = re.findall (r"('[^']*')|([0-9]+)", input_string)
res = ';'.join([a or b for a,b in x])
would do the trick. This leaves the ' characters in, a little bit more work
could get rid of them too.
More information about the Python-list