in reply to Regex AND

Of course, the most easy way is to concatenate your regular expressions, as they are all zero-width lookaheads:

m!^(?!CX36(5|6))(?!JA30[0-2])...!

But you should really give it more thought - why do you need to assert that some stuff is not present. In most parsing tools, you can order the recognition steps in such a way, that you don't need negative assertions, by ordering the more specific rules before the less specific rules. Efficiency will also become a matter if you have more than a few regular expressions and/or more than a few bytes to match on, that is, unanchored matches.

It might help if you'd tell us what parsing tool you are using, and why you think that your strings are all anchored at the beginning - as a very easy early-out optimization, I see that, for example, substr($_,0,1) ne 'J' && substr($_,0,1) ne 'C' will assert that none of your regexes match, which could be way faster than regular expressions given a suitably large alphabet to match - maybe you want something else? What problem are you trying to solve.

Replies are listed 'Best First'.
Re^2: Regex AND
by ady (Deacon) on Dec 02, 2004 at 14:30 UTC
    Yes indeed!, as you indicate Corion this combined regex does the trick, - for the specified example :
    ^((?!CX36(5|6))(?!JA30[0-2])(?!JA3(([2-8]\d)|(9[0-4])))(?!JA5.*)(?!(JA +6((0\d)|(1[0-3]))))(?!JA64[7-9])(?!JA687.*)(?!JA74[0-3])(?!JB5.*)(?!( +JY(((1|2)\d\d)|(3[0-3]\d))))(?!JY[3-9][5-9]\d)(?!JZ51(3|4)00.*))

    This seems to me the easiest way to solve the problem, though undoubtably not the most efficient. But the tradeoff does cut the cheese.

    Thanks a lot Allan