admin管理员组文章数量:1328022
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?
本文标签: javascriptregex match all characters after open bracket Stack Overflow
版权声明:本文标题:javascript - regex match all characters after open bracket [ - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742237165a2438288.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论