代码:
val = val.replace(/(^|[^\[])\^/g, '$1');
在我看来是无意义的。
function replace(regex, opt) { regex = regex.source; opt = opt || ‘’; return function self(name, val) { if (!name) return new RegExp(regex, opt); val = val.source || val; val = val.replace(/(^|[^[])^/g, ‘$1’); regex = regex.replace(name, val); return self; }; }
无意义
@alsotang
/(^|[^[])^/g
这玩意儿能匹配啥?
@DevinXian 啥都不行。^用得太风骚。
^
例子 /^ *[([^]]+)]: *<?([^\s>]+)>?(?: +"([")])? *(?:\n+|$)/.source.replace(/(^|[^[])^/g, ‘$1’)
结果:
" *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)"
哦,好像转义了反斜杠,应该是这样的:
匹配以^开头的^, 或者任何非[后的^ 其中
[^\[]
让这个正则可以跨越多行匹配。
@guotie 只要没有定位,随便跨行。这个正则用途挺特殊…
去掉前面不为[的^
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
在我看来是无意义的。
function replace(regex, opt) { regex = regex.source; opt = opt || ‘’; return function self(name, val) { if (!name) return new RegExp(regex, opt); val = val.source || val; val = val.replace(/(^|[^[])^/g, ‘$1’); regex = regex.replace(name, val); return self; }; }
无意义
@alsotang
这玩意儿能匹配啥?
@DevinXian 啥都不行。
^用得太风骚。例子 /^ *[([^]]+)]: *<?([^\s>]+)>?(?: +"([")])? *(?:\n+|$)/.source.replace(/(^|[^[])^/g, ‘$1’)
结果:
哦,好像转义了反斜杠,应该是这样的:
匹配以^开头的^, 或者任何非[后的^ 其中
让这个正则可以跨越多行匹配。
@guotie 只要没有定位,随便跨行。这个正则用途挺特殊…
去掉前面不为[的^