How find and replace a string in the HTML file

Discussion in 'Perl Misc' started by jussi, Oct 6, 2005.

  1. jussi

    jussi Guest

    hi gurus

    I need to replace some string in the html file but haven't manage to
    work it out.

    In a HTML file I have a string :

    ......<a href="javascript:CreateList(TopForm)"><img
    src="images/playselected.gif" bgcolor="#949494" align="right/"

    Which I need to replace with this one:


    I have look for exsample HTML::parser but couldn't understand how it
    works !!

    So please, give me exsample code how to find a string and replace it.

    Thanks advance
    jussi, Oct 6, 2005
    1. Advertisements

  2. hi gurus
    I'm CERTAINLY NOT a guru but

    my $str = "Mary had a large lamb";

    $str = s/large/little/g;

    might get you started

    Julia De Silva, Oct 6, 2005
    1. Advertisements

  3. Sorry That's
    my $str = "Mary had a large lamb";
    $str =~ s/large/little/g;

    Julia De Silva, Oct 6, 2005
  4. If you search this group, you'll find examples of how to use it.

    If the above is the only thing you want to replace, something like this
    may be sufficient:

    $html =~ s#<a\s+href.+?CreateList\(TopForm\).+?</a>#&nbsp;#is;
    Gunnar Hjalmarsson, Oct 6, 2005
  5. jussi

    jussi Guest

    Thanks Gunnar, it work fine !

    But when I use the same method to find and replace next string:

    href="javascript:popUpPlayFile('./PlayFile.asp?E:\\video\\506-TEST-VIDEO[email protected][email protected]%CH20so-',1)">

    With this:
    <a ref file://LINK_TO_VIDEO >

    And I do it like this

    $html =~
    s#<a\s+href"javascript:popUpPlayFile.+?506-TEST-VIDEO.+?>img<#<a ref
    file://LINK_TO_VIDEO >#is;

    This doesn't work. Any help would be nice ..

    jussi, Oct 7, 2005
  6. What works fine? Please provide context when replying to a message, as
    is recommended in the posting guidelines for this group:
    (Those who may be able to reply don't usually access the group via Google.)
    Do you possibly mean


    Where is the equality sign?

    What's 'img<'?
    You can help both yourself and us by checking your code _carefully_
    before asking hundreds of people for help.
    Gunnar Hjalmarsson, Oct 7, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.