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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |