in reply to Re^4: Regex match at the beginning or end of string
in thread Regex match at the beginning or end of string
Yeah, but instead of writing complicated lookaheads,
There is nothing complicated about /(?=.*term).
one may as well write: /pattern1/ && /pattern2/;
For two terms maybe. But how about for a variable number of terms?
which compared to the lookahead variant, has a better chance of being handled by the optimizer.
The optimiser?
Care to show some evidence of this "optimiser" in operation? Documentations? Any indication that it actually exists?
However, neither this, nor the suggested lookahead variant actually trigger only on "pattern1" followed by "pattern2", or "pattern2" followed by "pattern1"
That is only one of the constraints specified, which can be verified using @+ & @- after the match.
Have you any solution that satisfies the other two constraints? Namely:
without the need to use of multiple comparisons or duplicate usage of either patterns
For instance: ... and ... but ...
Bad choices do not make for good examples.
I offered a solution. Others have offered other solutions. The OP chooses.
But, I challenge you to construct the regex(es) required to match the terms: the, quick, brown, fox, jumps, over, the, lazy, dog, in any ordering, using some other technique.
Assuming you'll have a solution, we can then compare how the "optimiser" fares with the two variants.
|
|---|