Hi,
My knowledge of regular expressions is practically nothing and I'm tearing my hair out trying to correct some buggy code in PHP.
What it needs to do is change the path (by adding "newdirectory/" to the start of the path) for all images in the HTML that are relatively linked i.e. the path to the image does not begin with "http://", "https://" OR "/", where an image path is identified as being a string between single or double qoutes ending in .gif, .jpg, .jpeg or .png - this includes all images referenced in inline style backgrounds and as values in option tags for dropdowns.
Examples where then path should be matched and adjusted:
<img src="../image/my.gif" height="10px"> -> <img src="newdirectory/../image/my.gif" height="10px">
<div style='background-image: URL('image/my.png')' /> -> <div style='background-image: URL('newdirectory/image/my.png')' />
<option value="my.jpg"> -> <option value="newdirectory/my.jpg">
Examples where then path should NOT be matched:
<img src="http://mydomain/image/my.gif" height="10px">
<div style='background-image: URL('/image/my.png')' />
<option value="http://antoherdomain/my.jpg">
What I'm working with at the moment is /(?i)([^=\"\'\s]*?(\.(jp?g|gif|png)))/ but it doesn't exclude images with absolute paths.
Please advise.