最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - regex match all characters after open bracket [ - Stack Overflow

programmeradmin7浏览0评论

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 [.

Share Improve this question edited Sep 2, 2011 at 2:06 Mateen Ulhaq 27.3k21 gold badges119 silver badges152 bronze badges asked Sep 2, 2011 at 1:57 mroutdoors25mroutdoors25 351 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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?

发布评论

评论列表(0)

  1. 暂无评论