[Tutor] (no subject)
kushal.kumaran+python at gmail.com
Wed Mar 30 09:46:21 CEST 2011
2011/3/30 "Andrés Chandía" <andres at chandia.net>:
> I'm new to this list, so hello everybody!.
> The stuff:
> I'm working with
> regexps and this is my line:
> contents = re.sub("<u>l<\/u>",
> "le" ,contents)
> in perl there is a way to reference previous registers,
> $text =~ s/<u>(l|L|n|N)<\/u>/$1e/g;
> So I'm looking for
> the way to do it in python, obviously this does not works:
> contents =
> re.sub("<u>(l|L|n|N)<\/u>", "$1e", contents)
You will use \1 for the backreference. The documentation of the re
module (http://docs.python.org/library/re.html#re.sub) has an example.
Also note the use of raw strings (r'...') to avoid having to escape
the backslash with another backslash.
More information about the Tutor