in reply to How do you match

You could use the !~ operator. I like unless for this, though.
unless (/cr\d$/) { print "This entry didn't match!\n"; }
The other could be:
if ($_ !~ /cr\d$/) { print "Didn't match.\n"; }

Replies are listed 'Best First'.
RE: Re: How do you match
by Limo (Scribe) on Sep 29, 2000 at 00:33 UTC
    How would I append this rule to my existing regex?
      You can't "append" it per se. You can't just say you want part of a regexp to match and another part to fail for the thing to succeed. Regular expressions are meant to match something, not "not" match. There's a negative lookahead thing (?!pattern) but that wasn't meant for what you're trying to do. You need to design your regular expression to succeed, even if you intend to negate its results when you're done (like with unless or !~).

      Perhaps if you give us a few lines of input and tell us what is supposed to match, and if so, what part of that string you expect your regexp to pull out, and we can try and point you in the right direction (or even write it).

        Ok, here's (hopefully) a more complete example: Example strings to match:
        confederation-as-router: 1 2345 atlanta1-cr1 confederation-as-router: 1 2345 atlanta1-cr2 confederation-as-router: 1 2345 atlanta1-cr3 confederation-as-router: 1 2345 atlanta1-cr4 confederation-as-router: 1 2345 atlanta1-cr5 confederation-as-router: 1 2345 atlanta1-cr6 confederation-as-router: 1 2345 atlanta1-sr1
        open (FILE2, $file_2) or die "Couldn't open file: $!"; while (<FILE2>) { if ($_ =~ s/^confederation-as-router\:\W+\d\W+\d+\W//) { push(@file2, $_); } } </CODE> Currently, the regex will return:
        atlanta1-cr1 atlanta1-cr2 atlanta1-cr3 atlanta1-cr4 atlanta1-cr5 atlanta1-cr6 atlanta1-sr1
        Based upon the above example, I want it to ONLY return:
        atlanta1-sr1
        Is that clearer?