Javascript 正则表达式无效组
有人知道为什么会出现Javascript 正则表达式无效组,javascript,regex,Javascript,Regex,有人知道为什么会出现无效正则表达式:Invalid group错误吗 text.replace(/(?<!br|p|\/p|b|\/b)>/g, ">"); text.replace(/(?/g,”); 这个没问题: text.replace(/<(?!br|p|\/p|b|\/b)/g, "<"); text.replace(/JavaScript不支持lookbehinds。以下是获得相同行为的一种方法: text = text.repla
无效正则表达式:Invalid group
错误吗
text.replace(/(?<!br|p|\/p|b|\/b)>/g, ">");
text.replace(/(?/g,”);
这个没问题:
text.replace(/<(?!br|p|\/p|b|\/b)/g, "<");
text.replace(/JavaScript不支持lookbehinds。以下是获得相同行为的一种方法:
text = text.replace(/(br|p|\/p|b|\/b)?>/g, function($0, $1){
return $1 ? $0 : ">";
});
此方法来自以下博客条目:
这里是一个更新的