mroutdoors25
mroutdoors25

Reputation: 35

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 want to make the "location" variable to be all the contents after the [.

Upvotes: 1

Views: 8218

Answers (1)

NullUserException
NullUserException

Reputation: 85468

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?

Upvotes: 6

Related Questions