Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取与JQuery/Javascript或正则表达式中的模式匹配的所有字符串_Javascript_Jquery_Regex - Fatal编程技术网

获取与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);差不多。。它可能需要逃跑