Regular Expressions to Replace Strings

Andrew Kuchling akuchlin at
Wed May 16 12:03:04 EDT 2001

"Colin Meeks" <colinmeeks at> writes:
> > CM> UseWord="python"
> > CM> pat=re.compile(UseWord,re.I)

Group 0 corresponds to the match as a whole, so you could use \0 in
your replacement pattern.  Alternatively, you could write '(python)'
instead, which puts your string inside a group, which would then be
numbered group 1, but that's a bit silly unless there are other
components of the regex pattern that you want to ignore (for example,
if there was a \s* to catch leading whitespace, and you didn't care
what the whitespace was).


More information about the Python-list mailing list