Regular Expressions to Replace Strings
akuchlin at mems-exchange.org
Wed May 16 18:03:04 CEST 2001
"Colin Meeks" <colinmeeks at home.com> 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