emulating an and operator in regular expressions

Ross La Haye rlahaye at new.rr.com
Sun Jan 2 19:52:22 EST 2005


How can an and operator be emulated in regular expressions in Python?
Specifically, I want to return a match on a string if and only if 2 or more
substrings all appear in the string.  For example, for a string s = 'Jones
John' and substrings sg0 = 'Jones' and sg1 = 'John', I want to return a
match, but for substrings sg0 = 'Jones' and sg2 = 'Frank' I do not want to
return a match.  Because the expression 'A and B' is logically equivalent to
'not (not A or not B)' I thought I could try something along those lines,
but can't crack it.

Ross


-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 1724 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050102/5e66797d/attachment.bin>


More information about the Python-list mailing list