regular expression back references

Matthew ruach at chpc.utah.edu
Fri Aug 8 18:12:55 EDT 2003


Greetings, I am having a problem using back references in my regex and
I am having a difficult time figuring out what I am doing wrong. My
regex works fine with out the back refs but when I try to use them it
won't match my sample. It looks to me that I am using them no
differently then my examples and documentation but to no avail.

Here is my patteren:

macExpression = "^[0-9A-F]{1,2}(\:|\.|\-)[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}\1[0-9A-F]{1,2}$:

And this is how I am using it:

matched = re.match(macExpression, macAddress)

I am trying to match mac addresses in the following formats
0:a0:c9:ee:b2:c0, 0-a0-c9-ee-b2-c0 & 0.a0.c9.ee.b2.c0 etc.

I wasn't sure how to do it but then I read about back references and I
thought that all was well... Alas If any one could lend a hand I would
appreciate it very much.

-matthew




More information about the Python-list mailing list