Rod Adams <[EMAIL PROTECTED]> writes: > Eirik Berg Hanssen wrote: > >>Rod Adams <[EMAIL PROTECTED]> writes: >> >> >> >>> $re1 = /^ <-[x]>* x <-[x]>* $/; # match a string with exactly one >>>'x' in it. >>> $re2 = /^ <-[y]>* y <-[y]>* $/; # ditto 'y' >>> $re3 = /^ <-[z]>* z <-[z]>* $/; # ditto 'z' >>> >>> >>> $re7 = none($re1, $re2, $re3); # matches if there are 0 or 2+ of >>>each of x,y,z. >>> >>> >>>#7 I have no idea how to attack as a single RE in anything close to >>>approaching elegance. >>> >>> >> >> Depending on your idea of elegance ... anchored zero-width negative >>lookahead: >> >>$re7 = qr/^ (?!= $re1 | $re2 | $re3 ) /x;
Whoops. For "?!=", read "?!". Now imagine the quality of my Perl6 code ... >> Oh right. Perl6. Well, if I understand "<$re1>" correctly, I think >>this is what it will look like: >> >>$re7 = /^ <!before <$re1> | <$re2> | <$re3> > /; >> >> > That doesn't quite do it, but something along those lines is > possible. You'd have to make sure the look ahead/behinds match to the > end of the string, not just some substring. And then you'd have to put > in something to actually match the string. So possible, but not > straightforward in the least. $re1, $re2, and $re3 are already anchored: Covered. And it will match the empty string at pos()==0, given that the assertion is satisfied. This of course differs from a junction of three match objects, each matching the whole string at pos()=0, but that difference is in part to be expected (the point of the exercise was to avoid a junction), and in part trivial to fix: just add ".*". In the general case, it will be more complex, yes, but so will the match object returned by the junctive rule. Well, enough pattern matching. Junctions on the agenda, now! ;-) Eirik -- "So this is the Sword of Immortality? Huh? What's it doin' in a CRYPT?!" --- John S. Novak, III, quoting an unnamed player