in reply to Strip specific html sequence

I should add that the match is not at the beginning of a line. When used in the variable, it 'matches' many random line start characters, but ignores the match itself! A typical line of HTML I want to target is:

</div></div><div><div class="blue"></div></div>

The desired result is:

</div></div>

Replies are listed 'Best First'.
Re^2: Strip specific html sequence
by hippo (Archbishop) on Dec 10, 2017 at 16:42 UTC

    Break it down to just the lines you want and fix those in isolation. SSCCE:

    use strict; use warnings; use Test::More tests => 2; my $input = '</div></div><div><div class="blue"></div></div>'; my $expected = '</div></div>'; my $remove = '</div><div><div class="blue"></div>'; like ($input, qr/$remove/, 'Match found'); # Just for illustration $input =~ s/$remove//; is ($input, $expected, 'Strip successful');
    Searching has suggested this is silly to try without a cpan solution

    Quite right. If you start to attempt to parse HTML in this fashion you are starting down a long and slippery slope which ends in the belly of the grue. Recant now while there is still time.