in reply to Re^4: regex not matching how I want it to :(
in thread regex not matching how I want it to :(

so on the second pass of while the regex is more or less like this:

$line='<p><a href="xxx.html"> test1</a><br> <a href="test2.htm"> test2 +</a><br> <a href="test3.htm"> test3</a><br> <a href="test4.htm"> test +4</a><br>'; $line=~/<a href=\"(.*?)\.htm\">/ig; $tmp=$1; print "LINE: $line\n"; print "TMP: $tmp KK\n\n";

why is it matching: xxx.html"> test1
<a href="test2

and not "test2"? how do I make it match test2, thank you

Replies are listed 'Best First'.
Re^6: regex not matching how I want it to :(
by tybalt89 (Monsignor) on Oct 18, 2018 at 20:43 UTC

    Don't do multiple passes of the "while". In fact, don't do a "while" at all :)

    #!/usr/bin/perl -l # https://perlmonks.org/?node_id=1224264 use strict; use warnings; my $line = '<p><a href="test1.htm"> test1</a><br> <a href="test2.htm"> + test2</a><br> <a href="test3.htm">test3</a><br> <a href="test4.htm"> + test4</a><br>'; my @replacements = 'xxx0001' .. 'xxx0100'; $line =~ s/<a href=\"\K.*?(?=\.htm\">)/ shift @replacements /gie; print $line;