获取与JQuery/Javascript或正则表达式中的模式匹配的所有字符串
我对正则表达式很在行,需要帮助获取字符串中以获取与JQuery/Javascript或正则表达式中的模式匹配的所有字符串,javascript,jquery,regex,Javascript,Jquery,Regex,我对正则表达式很在行,需要帮助获取字符串中以[开头,以]结尾的所有字符串 Example: "This is the match [*more*] or [*less*]" And I want to get [*more*], [*less*] into an array 我尝试过类似的方法,但不正确:/\[\*([^}]+)\*\]/g尝试以下方法: var str = "This is the match [more] or [less]"; var you_arr = str.ma
[
开头,以]
结尾的所有字符串
Example: "This is the match [*more*] or [*less*]"
And I want to get [*more*], [*less*] into an array
我尝试过类似的方法,但不正确:/\[\*([^}]+)\*\]/g
尝试以下方法:
var str = "This is the match [more] or [less]";
var you_arr = str.match(/(\[.*?\])/g);
结果
您的arr
:(“[更多]”、“[更少]”)
添加“更多”和“更少”或“[更多]”和“[更少]”?或者这是一个格式错误?我找到了一些方法:@sunbabaphu:应该是“[more]”和“[less]”这应该给我所有匹配项:sourceString.match(/[.]]/g);差不多。。它可能需要逃跑