I want to find and replace (from an html page) all occurrences of src attributes in img tags. E.g., take
<img width="25" height="13" border="0" src="/images/flags/de.png">
and change the src attribute
I am currently using:
$info{content}=~s!(<img[^>]src=")(/.*)"!$http://$dest$2!gi;
where $dest is the URL I want to put.
My problem is that it finds the 1st occurrence and not the subsequent ones.
Isn’t the /g option supposed to replace all occurrences?
I’m sure the regex works for the next occurrence, because if i add my code line another time, the next occurrence is replaced.
Your attempt didn’t work because the greedy
.*in the middle of your pattern matched everything between the firstsrc=and the last".Making it non-greedy
.*?would help.