I am using a regex
/(?<=\[)(.*)/i
to match every character after a [
. A user will type something like:
hello this is [what i want
I want it it match what i want
. It seems to work on a regex tester: . When I use it in my code it doesn't work at all. Is this because I'm not using the right regex flavor? Here is my snippet:
var location = document.getElementById('locationField').value=(mandLineInput.match(/(?<=\[)(.*)/i));
I just want to make the "location" variable to be all the contents after the [
.
I am using a regex
/(?<=\[)(.*)/i
to match every character after a [
. A user will type something like:
hello this is [what i want
I want it it match what i want
. It seems to work on a regex tester: http://gskinner./RegExr. When I use it in my code it doesn't work at all. Is this because I'm not using the right regex flavor? Here is my snippet:
var location = document.getElementById('locationField').value=(mandLineInput.match(/(?<=\[)(.*)/i));
I just want to make the "location" variable to be all the contents after the [
.
1 Answer
Reset to default 6Javascript does not support lookbehind. BTW why are you using the i
flag? There are no letters in your regex.
How about:
var str = "hello this is [what i want";
var want = str.match(/\[(.+)$/)[1];
instead?