Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've been tasked to seek out a 16 digit number starting with a 4 that does not contain a state code on the same line to be entered into an application using the perl engine. I have come up with:
(4[0-9]{3}(([ -]?)[0-9]{4}){3})((?!WI|MN).)*$
However, the application automatically throws a /i at the end of the statement which causes this thing to error off. Is there another way to rewrite this? Thanks!

Code tags added by GrandFather

Replies are listed 'Best First'.
Re: Finding a string not containing a string
by ww (Archbishop) on Jan 18, 2012 at 02:00 UTC

    The XML says the regex snippet above looks like this:

    (4[0-9]{3}(([ -]?)[0-9]{4}){3})((?!WI|MN).)*$

    BUT, Anonymous Monk, there's nothing there to tell us where the /i is coming from. If you know, show us the code (in the smallest possible compilable snippet that exhibits the same failure)... and if you don't, do that anyway.

    PS: it's also going to help if you define "state code" as applied to the text against which you're trying the regex... and you might wish to read perlretut about negating regexen and negative character classes.

Re: Finding a string not containing a string
by thenaz (Beadle) on Jan 17, 2012 at 23:53 UTC
    You can control which modifiers apply to any portion of a regex. In the regex snippit below, "foo" will be matched in a case-sensitive manner (the "i" modifier will not apply).
    (?-i:foo)
Re: Finding a string not containing a string
by kennethk (Abbot) on Jan 17, 2012 at 22:31 UTC
    Please wrap code in <code> tags, as the instructions above the input field stated. As you can see, your posted regex has linkified ranges because you failed to do so. See How do I post a question effectively?.

    While your spec is a little odd, I interpret that to say you have a fixed Perl script that takes a string version of a regular expression as input, and applies it to some input file. If the old code applies the i modifier to your input, then you necessarily must change the code there to hit your spec. Please correct me if my understanding of the issue is incorrect.