Hi pavan474,

It sounds to me like your regexp might be something like s/www\.abc\.com/www.test.com/g (please show your code!), which is indeed a bit too simple. Please see Re^5: Grab input from the user and Open the file, where I showed how to use Regexp::Common to match full URLs and URI to parse them, and in your case you could use that same module to exchange the hostname.

Update: Upon rereading your post it sounds like you're not just exchanging hostnames in the URLs, but the same idea applies - use Regexp::Common to search for the full URLs and replace with whatever you like. Also, as I mention in the post I linked to, note that Regexp::Common does not match the #fragment part of URLs, so if you've got those you may need the alternate solution I presented.

Update 2: You mention XML files. Please note that a simple search/replace regex on an XML file may not be a good idea, as you could potentially modify parts of the file you don't want changed, or break its syntax. When dealing with XML/HTML, it's usually better to use an appropriate parser - see here and here for examples.

Hope this helps,
-- Hauke D

Minor Update: Clarified wordings.


In reply to Re: URL search and replace in the files (updated) by haukex
in thread URL search and replace in the files by pavan474

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.