I cannot get this regex string to work in Javascript:
var input = $("input").val();
var hi = "(?<=[^ ])" + input + "(?=[$ ])";
var reg = new RegExp(hi);
alert(reg);
The last line is not working, but it does work when the regex is valid. I put the variable into a second string for the full regex search before passing that one to the regex object. Why isn’t this regex query valid? (In case you are wondering, the chars in the brackets are space, zwsp, nbsp, and zwj.)
JavaScript regular expressions do not support look-behind.
They do however, support look-ahead, so if you really need the functionality you can reverse the input and write the expression “backwards”. If you want both look-ahead and look-behind at the same time, this gets a little complicated.
As you haven’t revealed what you’re actually trying to achieve, you may be able to avoid the zero-width matches and just use normal capture groups.