Regular Expression problem

Mike Fletcher mfletch at tpresence.com
Fri Sep 15 04:48:54 CEST 2000


>>> re.sub( r's(\w+)' , r'sGreatRegex\1', 'thisStuff')
'thisGreatRegexStuff'

Note the use of the string regex definition for the re.sub function.
Compiled regex objects also have .sub methods, which, of course, don't need
to re-specify the regex string.

HTH,
Mike

-----Original Message-----
From: vmilitaru at sympatico.ca [mailto:vmilitaru at sympatico.ca]
Sent: Thursday, September 14, 2000 8:00 AM
To: python-list at python.org
Subject: Regular Expression problem


Greetings. I am posting this in the hope that it will somehow end up on
comp.lang.python.
I am using Python2b and can't get over the following RE problem:

myregexx = re.compile(r'Table Name(\W+)', re.IGNORECASE)
ssss = re.sub( myregexx , r'."""\nclass \1 (base_class):\n"""', ttt)

I basically want to re-use the word matched with (\W+) as part of the
output. In Perl, I'd use the $1 variable.
In Perl, I'd use the $1 variable. My initial understanding was that \1 is
the Py equivalent.
But since this obviously doesn't seem to be the case, and re-reading the
on-line docs for the 100th time doesn't seem to help anymore, could somebody
put me on the right track here.

Regards,
vio


-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list