eddmund has asked for the wisdom of the Perl Monks concerning the following question:
I think the problem is related to my use of the negative Lookahead. Could anybody point me to the right direction? Thanks, rob.#!/usr/bin/perl -w use strict; my @strings = ( '<a href="#1">HIT<b>MUST MATCH</b></a> <a href="#2">2</a>', '<a href="#1">HIT<a name="MUST NOT MATCH">-</a> <a href="#2">2</a>' ); foreach my $string (@strings) { "" =~ /()/; # set $1 to false $string =~ / ( # the whole match should be catches as $1 HIT # start at the first found "HIT" (?= # begin of positive Lookahead [^<]*? # zero or more characters other than "<" (?! # start a negative Lookahead <a[^>]*?> # an opening a tag is forbidden ) .*?<\/a> # any characters until the closing a tag ) # end of positive Lookahead .*? # catch all chars after HIT, <\/a> # non-greedy until the first closing a tag ) /x; print "\nstring:\t$string\n"; if ($1) { print "match:\t$1\n" } else { print "NO match!\n" } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: negative Lookahead or
by wog (Curate) on Nov 12, 2001 at 07:39 UTC | |
by eddmund (Initiate) on Nov 12, 2001 at 08:05 UTC | |
by wog (Curate) on Nov 12, 2001 at 08:15 UTC | |
by eddmund (Initiate) on Nov 12, 2001 at 21:00 UTC |