\number parameter in regular expression

Michael Fuhr mfuhr at fuhr.org
Sat Sep 25 16:10:49 CEST 2004

pit.grinja at gmx.de (Piet) writes:

> I am trying to understand the correct use of the \number parameter in
> pythons regular expressions. I belive that the following should work
> import re
> pattern = re.compile("([a-zA-Z]*)(.*)(\d{4}-\d{2}-\d{2})\1")
> search = pattern.search("Date#ThisIsASpacer2004-09-25Date")
> print search.groups()
> But it doesn't, because the RE doesn't match.
> I thought that the "\1" thing indicates that the respective part of
> the string in question should match the one that is located in
> search.group(1).

Read the intro to the re documentation:


Hint: what does \1 mean in a string that's not used as a regular

Michael Fuhr

More information about the Python-list mailing list