Why no RE match of A AND B?

Paddy paddy3118 at tiscali.co.uk
Sun Mar 2 16:00:12 EST 2003


Just looking through the docs to confirm it and their seems to be no regular expression 
construct that matches 'A and B' - an equivalent to the '|' character that matches A or B
To paraphrase the documentation it could be documented as:

   "&"
A&B, where A and B can be arbitrary REs, creates a regular expression that will match both 
A and B in any order. An arbitrary number of REs can be separated by the "&" in this way. 
This can be used inside groups as well. REs separated by "&" are tried in arbitrary order, 
the beginning of the first matching branch up to the end of the last branch that allows 
the complete pattern (all branches) to match is considered the span of the match.

I envision it being used where a string is accepted at present if it matches multiple REs.
The REs could be rewritten as r"<RE#1>&<RE2>&<RE3>...".

The use of "&" could be supported by more efficient, (simultaneous?),  matching of all 
branches of the "&" construct - if such algorithms exist!

  Just an idea,

   Paddy.





More information about the Python-list mailing list