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

on the other hand Regexp::Debugger - amazing tool, thank you. It shows what the problem and it is what I suspected, but I have no idea why is it matching this way and I have no idea how to fix this. As you see in my code I have a s/ replace and after first replace the matching is weird
  • Comment on Re^4: regex not matching how I want it to :(

Replies are listed 'Best First'.
Re^5: regex not matching how I want it to :(
by glwa (Acolyte) on Oct 18, 2018 at 20:28 UTC

    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

      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;