我需要从正则表达式匹配搜索中排除特定的双字符字符串“[?”

I need to exclude the specific two-character string `[?` from a regex match search

我正在使用此正则表达式字符串来查找周围有白色 space 或不属于小数部分的所有句号、感叹号和问号:

/\.(?=\s|$)|\?(?=\s|$)|\!(?=\s|$)/g

我正在使用 mark.js 来突出显示此 RegEx 字符串。我如何修改这个字符串(或使用另一个字符串),使其不会突出显示紧跟在括号之后的问号,或者 [?

这是我的代码:

function Highlight() {
var instance = new Mark(document.getElementById("example"));

instance.unmark();
instance.markRegExp(/\.(?=\s|$)|\?(?=\s|$)|\!(?=\s|$)/g);

}

window.onload = Highlight();
mark {
    background: pink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"></script>
<div id="example">
<p>This is an example paragraph. I would like all the periods to be highlighted. Woohoo! This works very well! Yay! Alright, onto question marks. This is demo2. [? flagged ?] 5.5 is a number. 0.3374 is another number. Does this work?</p>
</div>

Mark.js 也有一个 unmark() 方法来取消标记,但我不知道如何将 RegEx 与 unmark() 一起使用。非常感谢您的帮助。

负向回顾 (?<!\[) 被插入到正则表达式 \? 之前,这意味着正则表达式将采用前导字符不是 [?。您可以在否定回顾集内添加任何其他字符,以排除 ? 和其他前面的字符。

警告:并非所有浏览器都支持此功能。

另一种解决方案是在 ? 之前使用正常的否定集 [^\[],就像这样 /\.(?=\s|$)|[^\[]\?(?=\s|$)|\!(?=\s|$)/g。但是这个正则表达式也选择前面的字符。你必须在你的代码中处理它。

function Highlight() {
var instance = new Mark(document.getElementById("example"));

instance.unmark();
instance.markRegExp(/\.(?=\s|$)|(?<!\[)\?(?=\s|$)|\!(?=\s|$)/g);

}

window.onload = Highlight();
mark {
    background: pink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"></script>
<div id="example">
<p>This is an example paragraph. I would like all the periods to be highlighted. Woohoo! This works very well! Yay! Alright, onto question marks. This is demo2. [? flagged ?] 5.5 is a number. 0.3374 is another number. Does this work?</p>
</div>