Re: [MacPerl-AnyPerl] lookahead - (match if no macth)

[email protected] (allan) Tue, 30 Oct 2001 18:10:30 +0100
Newsgroups perl.macperl.anyperl
Message-ID <[email protected]>
thanks a lot - it worked.
but then i found out i need a more elaborate regexp, (see new below). it
almost works but wont match if the string "lookaround" appear after the
html-reference. so this one would match correctly if matched

src="aa1.gif"
src=aa2.gif
src=aa3.gif
src=aa4.gif
src="aa5r.gif"
src=aa6.gif

ive included comments so maybe someone can "read it loud" where its wrong
thanks again
allan
______

file:
src="aa1.gif" src="aLOOKAROUND.gif" stuff src=aa2.gif
src=aa3.gif src="LOOKAROUND.gif" stuff src=aa4.gif
src="Lookahea_LOOKAROUND_whatever.gif" src="aa5r.gif" src=aa6.gif


#!/usr/bin/perl -w
use strict;
open FILE, ":1.txt" or die $!;
while (<FILE>) {
	while(/(\w+=			# one or more alphanumeric, foollowed by =
		"?					# followed by an optional "
		(?!.*lookaround)	# followed by 0 or 1 more chars as long as we dont
match lookaround
		.*?					# followed by any numbers of chars (non greedy)	
		\.[a-z]+			# followed by . and 1 or more letters
		"?)					# followed by an optional "
		/igx) 
		{
		my $s = $1;
		print $s , "\n"
	}
}


> Try something like
> 
>         /(\w+="(?![^"]*lookaround).*?\.[a-z]+"?)/ig
> 
> --
>         Bart.