I have some markup that includes images with the following src
attribute:
https://url.com/image/img.jpg
I want to replace any image (or href
) that contains /image/
in its path. So the result would be:
https://newurl.com/img.jpg
I've tried using:
/src="(?:[^'\/]*\/)*([^']+)"/g
but not sure how to get it to only match /image/
paths, also when I change src
to href
it doesn't seem to allow me to replace both.
To clarify, I'm parsing plain text that happens to contain html strings. Also, I need to be able to maintain the file name, but replace the host address.
Update: Here's a jsfiddle of what I have so far. Although it works for the src
, it's not taking into account the /image/
in the path, also it removes the href.