regex match all characters after open bracket [
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.com/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=(commandLineInput.match(/(?<=\[)(.*)/i));
I just wan开发者_StackOverflow社区t to make the "location" variable to be all the contents after the [
.
Javascript 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?
精彩评论