Making regex suck less
Max M
maxm at mxm.dk
Tue Sep 3 03:58:54 EDT 2002
Carl Banks wrote:
>>What would the equivalent of r"(.)(.)(.)\3\2\1"
>>This means a "palindrome of 6 characters"
>>But it is unlikely that the human readable processor would understand
>>that (isn't it??)
Why not just write the parts of the regex as named strings?
like::
name = '[a-zA-Z0-9_.]+'
at = '@'
dot = '\.'
topDomain = 'com|org|dk'
email = name + at + name + dot + topDomain
instead of::
email = '[a-zA-Z0-9_.]+@[a-zA-Z0-9_.]+\.com|org|dk'
Well my syntax is most likely wrong as I suck at regex, but the meaning
should be clear enough.
More information about the Python-list
mailing list