我想在两个方括号之间提取任何内容,同时在数组中保持不匹配的字符串,直到下一个匹配点。
例如:
var string = "Keep [[this]] and [[this too]]";
// Some code
// output = ["Keep ", "this", " and ", "this too"];
最快的方法是什么?
答案 0 :(得分:4)
带有捕获组的正则表达式的split
method执行此操作:
var string = "Keep [[this]] and [[this too]]";
string.split(/\[\[(.+?)\]\]/g)
// Array ["Keep ", "this", " and ", "this too", ""]