我有一个类似[[user.system.first_name]][[user.custom.luid]] blah blah
我想匹配user.system.first_name
和user.custom.luid
我构建了/\[\[(\S+)\]\]/
,但它匹配user.system.first_name]][[user.custom.luid
。
知道我做错了吗?
答案 0 :(得分:3)
答案 1 :(得分:3)
使用?
使其非贪婪,以匹配尽可能少的输入字符。你的正则表达式将是 /\[\[(\S+?)\]\]/
var str = '[[user.system.first_name]][[user.custom.luid]] blah blah'
var reg = /\[\[(\S+?)\]\]/g,
match, res = [];
while (match = reg.exec(str))
res.push(match[1]);
document.write('<pre>' + JSON.stringify(res, null, 3) + '</pre>');
答案 2 :(得分:1)
答案 3 :(得分:1)
我认为/[^[]+?(?=]])/g
是一个快速正则表达式。原来是44步完成
[^[]+?(?=]])
var s = "[[user.system.first_name]][[user.custom.luid]]",
m = s.match(/[^[]+?(?=]])/g);
document.write("<pre>" + JSON.stringify(m,null,2) + "</pre>") ;
&#13;