in reply to Regex AND

I posted earlier that regex::assemble wouldn't help with your problem, because it's "regex or" not "regex and". But it now occurs to me that in your particular situation, it might help -- efficiency wise. Because you are looking for a regex that does not match several regexes. And actually, in boolean logic that is the same as a does not match "regex1 or regex 2 or regex3". So before you wound up with something like
(?!regex1)(?!regex2)(?!regex3)
But you could use regex::assemble to do
my $andedRegexes = Regexp::Assemble->new; $andedRegexes->add( 'regex1' ); $andedRegexes->add( 'regex2' ); $andedRegexes->add( 'regex3' ); #regex is now 'regex(1|2|3)' #which is more efficient
and then do a negative lookahead on that. I'm not sure of the quoting syntax here though.
$negatedAndedRegexes = (?=qr($andedRegexes))
Actually I'm pretty sure that's wrong syntax. But you get the idea.

(Could someone correct that?)

Hope this helps!

Thomas.

Replies are listed 'Best First'.
Re: Actually, regex::assemble would help!
by ady (Deacon) on Dec 04, 2004 at 12:56 UTC
    Yes Thomas, if i chose to open the source and recode the parser, i could walk down that road.

    However my situation is more like (as pointed out by eyepopslikeamosquito above) the Perl Cookbok 6.18 :

    "... So you need to write a single pattern that matches either of two diffe +rent patterns (the "or" case) or both of two patterns (the "and" case +) or that reverses the sense of the match ("not"). This situation arises often in configuration files, web forms, or comm +and-line arguments. ..."

    So with that i do consider my problem solved, -- even though as it's written in the recipe :

    ...It's not a pretty picture, and in a regular program, you'd almost n +ever do this"...

    Sic!

    Best Regards / Allan Dystrup

    "...this very place is the Land of Lotuses..." / Hakuin Ekaku Zenji