How to Re this string!
whisper at oz.net
Tue Aug 13 06:47:45 CEST 2002
> 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
r"\d\d \d \d\d \d\d \'[^']*?\' \'[^']*?\' \'[^']*\' \'[^']*?\' \'[^']*?\' \d
> 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 ";"
I'm not sure what you mean by the final string, but if it's 'sunitw2k' in
this case, then this will have the final string in match.group(1):
r"\d\d \d \d\d \d\d \'[^']*?\' \'[^']*?\' \'[^']*\' \'[^']*?\' \'([^']*?)\'
If you mean the whole matched string, that's in match.group(0).
> Could someone please help mw with an Re.exp for this.
These patterns depend on the format of the string being _exactly_ what you
posted: if two digits (such as "20" above) can be only one digit if the
value is less then 10, this re will fail (this could be fixed). It will not
fail on empty strings '' if the quotes are there.
Seattle, WA USA
More information about the Python-list