Edit: the proposed question/answer does not solve my problem: Let me rephrase: find the string between <img src="
and " />"
and replace it with the original plus another string like ?w=500
. I thought this might be doable with regex, but I'd be happy to do it in any JS way also. I don't have jQuery in this context though....
Let's say I have a string containing some markup with image tags, among other things, like this:
<img src="supercool.jpg" />
<p>very cool</p>
<img src="mega.jpg" />
How can I, with regex or otherwise, append a given string (say ?w=500
) to each src attribute, so that I end up with
<img src="supercool.jpg?w=500" />
<p>very cool</p>
<img src="mega.jpg?w=500" />
I've looked at similar questions on SO but haven't been able to devise a solution, my regex skills are just too poor:)