2011/3/30 "Andrés Chandía" <and...@chandia.net>: > > > I'm new to this list, so hello everybody!. >
Hello Andrés > 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, > i.e. > > $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. -- regards, kushal _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor