获取与JQuery / Javascript或正则表达式中的模式匹配的所有字符串

时间:2014-07-17 22:29:09

标签: javascript jquery regex

我对正则表达式感到非常糟糕,需要帮助才能获得以[开头且以字符串结尾]结尾的所有字符串。

Example: "This is the match [*more*] or [*less*]" 

And I want to get [*more*], [*less*] into an array

我尝试过这样的事情,但不正确:/\[\*([^}]+)\*\]/g

1 个答案:

答案 0 :(得分:1)

试试这个:

var str = "This is the match [more] or [less]";
var you_arr = str.match(/(\[.*?\])/g);

结果your_arr("[more]","[less]")

相关问题