Regex for repeated character?

Paul McGuire ptmcg at austin.rr.com
Thu Jun 16 09:44:48 EDT 2005


One more bit, add this on to the code in the previous post:

print "collapse repeated characters"
repeats.setParseAction(lambda s,l,toks: toks[0][0])
print test,"->",repeats.transformString(test)

Gives:

collapse repeated characters
foo ooobaaazZZ -> fo obazZ




More information about the Python-list mailing list