in reply to Pattern matching

This is untested tested (see below)...

m#/lawyers/(?!.*LDS).*~Firms\.html#

But as perlre states, "Sometimes it's still easier just to say: if (/bar/ && $` !~ /foo$/) ."

Updated: Switched m!! to m##.

Update: Here's a test. I think I captured the intent behind your question:

use strict; use warnings; my @strings = ( '/lawyers/stuffLDSstuff/~Firms.html', '/lawyers/stuffnotstuff/~Firms.html' ); foreach my $string ( @strings ) { print $string; if( $string =~ m#/lawyers/(?!.*LDS).*~Firms\.html# ) { print " matches.\n"; } else { print " doesn't match.\n"; } }

Dave

Replies are listed 'Best First'.
Re^2: Pattern matching
by johnnywang (Priest) on Dec 29, 2004 at 07:04 UTC
    Just want to point out the reg will also exclude those with "LDS" after the "html", e.g.:
    /lawyers/stuffnotstuff/~Firms.html?param=LDS
    I confess I can't think of a way to solve that.

      You can do that by combining the two .* aspects of the pattern:

      m{ /lawyers/ (?: (?!LDS) . )* ~Firms.html }x

      Hugo

Re^2: Pattern matching
by bedanta (Novice) on Dec 29, 2004 at 06:47 UTC
    Thanks the answer was of great help