我正在对一些标记化的字符串进行替换,如下所示:
var myString = "I would like to replace the following token <<start<arg1,arg2 >>> in this string"
OR
var myString = "The expression has an optional <<start<arg1,arg2,arg3 >>> third argument"
在令牌中,我想捕获 2 或 3 个字母数字字符串并将其传递给正则表达式回调函数:
myString.replace(regExExpression, function(m, arg1, arg2, arg3) {
return foo(arg1, arg2, arg3);
});
什么正则表达式将匹配 myString 的两个版本,捕获 arg1、arg2 和可选的 arg3?