in reply to Search and replace in html

Do you want something like this?
#!/usr/bin/perl -w use strict; while(<DATA>) { next if /<HTML.*?>/gi; next if /<\/HTML.*?>/gi; print; } __DATA__ <HTML> <HEAD><TITLE>Homepage</TITLE></HEAD> <BODY> <a href='blah.html'> man blah.pl</a><BR> <a href='blah.html'> man blablablah.sh </a><BR> <a href='blah.html'> man blablablablah.sh </a><BR> </BODY> </HTML>
update ... or maybe ...
#!/usr/bin/perl -w use strict; while(<DATA>) { s/<HTML.*?>//gi; s/<\/HTML.*?>//gi; print; } __DATA__ <HTML><HEAD><TITLE>Homepage</TITLE></HEAD> <BODY> <a href='blah.html'> man blah.pl</a><BR> <a href='blah.html'> man blablablah.sh </a><BR> <a href='blah.html'> man blablablablah.sh </a><BR> </BODY> </HTML>

Replies are listed 'Best First'.
Re: Re: Search and replace in html
by Limbic~Region (Chancellor) on May 09, 2003 at 00:22 UTC
    LameNerd,
    Try your code with:
    __DATA__ asdfasdf asdfasdf asdfasdf<htMl >asdfasdf blah </htmlasdf> foo bar </html >asdfasdf asdfasdf
    I am not saying that Anonymous Monk should even be attempting to do this as a roll your own solution (go CPAN) - just thought I would point out a weakness or two.

    Cheers - L~R

      The output is ...
      asdfasdf asdfasdf asdfasdfasdfasdf blah foo bar asdfasdf asdfasdf
      What's wrong with that? It got rid of the html tags?
      I think that is all Anonymous Monk wanted to accomplish.
      That is also why I stated in my original post ...

      Do you want something like this?
        LameNerd,
        From the original post:
        $TheLine =~ s/<html>([^\n]*)<\/html>/$1/i;

        The anonymous monk appears to want was it between the HTML tags.
      • You have included what is before and after
      • You have not included a fake html tag

        It doesn't really matter - it just doesn't look like what the anonymous monk was after

        Cheers - L~R