Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Search and replace in html

by LameNerd (Hermit)
on May 08, 2003 at 23:31 UTC ( [id://256709]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://256709]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found