Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I know how to program Perl a bit, but dont have enough regex voodoo knowhow for this particular snippet..Any pointers much appreciated..
What I need to do is provide a single regex that will return a false when it encounters any one of a list of numbers..This is actually for a config file (so I cant use conventional boolean logic, worse luck).. using the Perl cookbook, and some prayer, I came up with the following regex,
/^(?!.*7000|7777|7778|3886200|2200|8488|3406|9100|29389988|7688|5000|2 +0|3408|3404|7648).*[0-9]+/
What this perfectly awful piece of code is supposed to do is, when input a number, if the number is in the list above (ie: 7000, 7777, 7778 etc), it should return a FALSE.. ie, the boolean match should fail..if any other number is input, it should pass..
The problem is, although the regex should allow the input of a number like "70000" (note, there is an extra 0), it actually throws it out (I suspect this is because it matches the 7000)..
So, I suppose the general question is, the Perl cookbook describes how to incorporate boolean logic into a regex (recipe 6.17).. but it stops short of saying how to use a list of values instead of just one.. and simple | separated OR-ing doesnt seem to work.. so, any pointers on how to use a list of values much appreciated..
Muchos gracias
PS: I know its ugly ugly code, I see several .* matches *oh, the horror*. but I honestly didnt see any other way to catch everything I wanted to..
|
|---|