Backreference within a character class

Alex alex at somewhere.round.here
Thu Feb 24 17:18:00 EST 2000


> I want to match "XIX" but not "XXX" or "WOW" but not "WWW".

This seems to do the trick:

import re

matcher = re.compile(r'(.)(?!\1).\1').match

print matcher('XAX')
print matcher('XXX')

Alex.



More information about the Python-list mailing list