emulating an and operator in regular expressions

Terry Reedy tjreedy at udel.edu
Mon Jan 3 14:56:34 EST 2005


"Craig Ringer" <craig at postnewspapers.com.au> wrote in message 
news:1104750397.26918.1.camel at rasputin.localnet...
> On Mon, 2005-01-03 at 08:52, Ross La Haye wrote:
>> How can an and operator be emulated in regular expressions in Python?

Regular expressions are designed to define and detect repetition and 
alternatives.  These are easily implemented with finite state machines. 
REs not meant for conjunction.  'And' can be done but, as I remember, only 
messily and slowly.  The demonstration I once read was definitely 
theoretical, not practical.

Python was designed for and logic (among everything else).  If you want 
practical code, use it.

if match1 and match2: do whatever.

Terry J. Reedy






More information about the Python-list mailing list