I've just started using a WYSIWYG tool and the images are broken links unless I include the "http://domain.com/" before them. I've been using the short-cut <img src="directory/image.jpg" /> method.

So to fix the bug I've tried doing a simple regex during the edit: $content=~s{(img src=")}{$1$httpURL}g; and then I planned to remove it after the form posting/submitting.
Later, realized that there is the chance of remote urls being used as well and I don't want to put two or more http-urls back to back (as they don't belong).

I basically need a good way to search and replace only image sources that don't contain "http://" already. Here's a couple of things I've tried:

my $http='http://domain.com/'; my $sample='<img src="pics/local.jpg" alt="" /> <img src="http://remote.com/pics/remote.jpg" /> more confusion, just in case: 3:00pm 12/12/12 other urls <a href="http://fake.com"> http://fake.com</a>'; #-- THIS ------------------- $sample=~s{(img src=")(\w?)[^:]}{$1$http$2}g; # something from my book, POSIX ? not very clear #-- OR --------------------- $sample=~s/(img src=")(\w.+?)(:?)/"$1$http$2"if(!$3)/eg; #-- END --------------------

I also failed on other discarded variations, so I gave up and need your help.
Any help appreciated in advance.


In reply to Find and replace with regex by JayBee

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.