I have this piece of code:
_regex = /((?<!placeholder)\w+(?:\s*=\s*(?:"[^"]*"|'[^']*')))/;
imgTag = imgTag.replaceAll(_regex, ' ');
Have also tried this instead:
imgTag = imgTag.replace( new RegExp( /((?<!placeholder)\w+(?:\s*=\s*(?:"[^"]*"|'[^']*')))/, "gi" ), ' ');
But my code never gets passed this line:
_regex = /((?<!placeholder)\w+(?:\s*=\s*(?:"[^"]*"|'[^']*')))/;
Or this line:
imgTag = imgTag.replace( new RegExp( /((?<!placeholder)\w+(?:\s*=\s*(?:"[^"]*"|'[^']*')))/, "gi" ), ' ');
So the problem is in my RegEx, right?
I can’t see it, can anyone please shed a light?
Thanks!
Javascript doesn’t support lookbehinds. You can’t write this:
Use a lookahead instead:
You’ll need to adjust your replacement string too, because this matches extra characters just before the start of what you want to replace.
Also this won’t work:
var regex = new Regexp(/.../, "gi");Write this instead:
var regex = /.../gi;