I'm using regex to replace image source urls in an html file.
I want for example to replace img/ with <?= $folder ?>/img/
The issue:
When I run the regex multiple times it will replace img/ again, creating:
<?= $folder ?>/<?= $folder ?>/img
..and so on. Is there a way to tell regex to replace img/ if not already <?= $folder ?>/img ?
I am trying /^(?:(?!<?= $folder ?>/img).)*$/ but not sure how to first match and check if that it doesn't already contain <?= $folder ?>/img
[PLACEHOLDER], then do your replace, then replace[PLACEHOLDER]with your full string again. I believe you can do your replace with just a single RegEx, but this way would be an alternative that's a little more linear./^(?:(?!<?= $folder ?>\/img).)*$/works fine and doesn't replace if same string is already there in input