in reply to old Perl regex problem

First, I don't think the regular expression you have works at all. BrowserUk's version works nicely.

I don't remember if look-behind was supported in 5.004. If so, you might use something like: /^PH.*(?<![HI]-000)$/

One question: is a file named "PH-000" ok, or not? From your description, I'd think it was but the solutions so far (including the one above) don't allow it. This would: /^PH(.*)/ and $1 !~ /[HI]-000$/;

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: old Perl regex problem
by GhodMode (Pilgrim) on Aug 02, 2002 at 14:01 UTC

         It works on 5.6.1. Someone tested it for me.
         Using the info that I put in the original post, PH-000 should not be ok. I didn't really think about that too much because I know the format of the actual files that I'm going through, but my original regex would probably be better represented with ".+" after the "PH" instead of ".*?".
    Here's an actual file name: PH0022080209401500001PE-000
         BrowserUk's version would work great, but I'm reading the pattern from a configuration file and I can't change anything outside of the slashes.

    Invulnerable. Unlimited XP. Unlimited Votes. I must be...
            GhodMode
      I doubt it worked under 5.6.1. Perhaps it was tested, but then the test was insufficient.
      /^PH.*?[^(H\-000)(IF\-000)]$/
      will reject any file name ending in a 0, including
      PH0022080209401500001PE-000
      yet that is a legal file name according to your specifications.
      $ /opt/perl/5.6.1/bin/perl -wle 'print "Reject" unless "PH0022080209401500001PE-000" =~ /^PH.*?[^(H\-000)(IF\-000)]$/' Reject $
      Abigail