ftumsh has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to implement a -ve regex using only the =~ construct. ie The regex should match if a string is not found in the source string. I am using a daemon that accepts regexes and applies them to files, which is why I am stuck with the =~ construct.
Here is a sample string:L,0010,8001149805,003,20121015,0600,267,204193,20121015,1300,,GBFER,204193
I should like to have a positive match if the string doesn't contain GBFER and GBFOO. Just like !~ /(?:GBFER|GBFOO)/.
All I can know about the string is that it starts with "L," and has a fixed number of commas. Everything between the commas may be zero or multiple alphanumeric. Also, the bit I am wanting to test will be between the 11th and 12th commas.
I did have the (as I thought hours ago) wizzo idea of having a conditional regex with a look ahead assertion. If the lookahead matched, I'd use a regex that always failed. If the look ahead didn't match, I'd use a regex that always matched.
However, after hours of google and RTFM, I can't get it to work (it is another node)...
So, any and all comments, ideas, pointers, welcomed.
Warmly John
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Writing a negative regex using =~
by betterworld (Curate) on Oct 17, 2012 at 10:01 UTC | |
by ftumsh (Scribe) on Oct 17, 2012 at 10:41 UTC | |
by ftumsh (Scribe) on Oct 17, 2012 at 10:53 UTC | |
Re: Writing a negative regex using =~
by ftumsh (Scribe) on Oct 17, 2012 at 10:54 UTC | |
Re: Writing a negative regex using =~
by kcott (Archbishop) on Oct 17, 2012 at 09:56 UTC | |
Re: Writing a negative regex using =~
by Anonymous Monk on Oct 17, 2012 at 09:50 UTC |