\number parameter in regular expression

Michael Fuhr mfuhr at fuhr.org
Sat Sep 25 10:10:49 EDT 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:

http://docs.python.org/lib/module-re.html

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

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



More information about the Python-list mailing list