in reply to Re^4: substitute character
in thread substitute character

See perlre on backreferences, but in the long run, you want something like HTML::TokeParser or HTML::TreeBuilder, because modifying HTML using regular expressions only works for reasonably well-formed HTML.

Replies are listed 'Best First'.
Re^6: substitute character
by gem555 (Acolyte) on Sep 02, 2009 at 09:56 UTC
    #!/usr/bin/perl my $line; while (my $line = <DATA>){ $line =~ s/<span><p>(.*)/defined ($1) ? "<" : '</p><p>'/eg; print $line; } __DATA__ <span><p>This affected me deeply because < I was being treated for dep +ression then. < felt she was replacing me as mother and grandmother.
    This is just printing '<'. But the output needed is
    <span><p>This affected me deeply because </p><p> I was being treated f +or depression then. </p><p> felt she was replacing me as mother and g +randmother.
    A reply falls below the community's threshold of quality. You may see it by logging in.