Finding the intersection between two regexes

Dirk Koopman djk at
Mon Apr 21 09:45:09 BST 2014

On 21/04/14 03:14, Mark Fowler wrote:
> On Sunday, April 20, 2014, David Cantrell <david at> wrote:
>> Can anyone point me at some code on the CPAN that, given two regexes,
>> can figure out whether there are any bits of text that will be matched
>> by both?
> I'm not sure I understand the question here, or moreover why you want to do
> it just an intellectual exercise?
> If it's just a matter of wanting a single Perl regular expression that can
> match something iff both of these other regular expressions would match,
> surely you can just do this by inserting the second regular expression at
> the beginning of the first encapsulated in a zero-width positive look ahead
> assertion (with suitable variable length doodads to pad if they're not
> anchoring at the same place in the string.)
> What the link is talking about seems to be converting a regular expression
> down into a finate state machine and then combining that finate state
> machine with another finate state machine (I.e. non deterministic, being
> turned back into deterministic with maths). I can see how that's possible
> for a strict regular expression, but as you say, not for a true Perl
> non-regular regular expression.
> So...why do you want to do this?

This may be related to the question I asked recently about turning (up 
to) a few hundred REGEXes into one giant REGEX. The goal being to test 
all those disparate REGEXes in the most efficient way possible on a string.


More information about the mailing list