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

I want to match two patterns 1) ng/2.0, and 2) ng/ I have to match for ng/ only, on the same data as I match ng/2.0. So I need a pattern which says match ng/NOT 2.0. please help..

Replies are listed 'Best First'.
Re: Pattern matching
by ihb (Deacon) on Dec 15, 2004 at 05:11 UTC

    The way to say that you don't want something is using a negative lookahead assertion which is (?!...). In your case it'll be

    m[ng/(?!2\.0)]

    Related documents:
    perlre - Perl regular expressions
    perlrequick - Perl regular expressions quick start
    perlretut - Perl regular expressions tutorial

    Hope this helps,
    ihb

    See perltoc if you don't know which perldoc to read!
    Read argumentation in its context!

Re: Pattern matching
by Errto (Vicar) on Dec 15, 2004 at 05:12 UTC
    One pattern might look like $data =~ /ng(?!2\.0)/. This is called using a negative look-ahead assertion, a fancy term meaning that you are looking for a pattern to not match at a given location. You can find much more in perlre.