匹配,除非存在“转义”字符;必须联机和背靠背工作

Match unless “escape” character is present; must work inline and back-to-back

本文关键字:联机 工作 背靠背 字符 存在 转义 匹配      更新时间:2023-09-26

这个问题与Match非常相似,除非"逃逸;字符存在,但是批准的解决方案并不是在所有情况下都有效。

在我的场景中,我使用javascript,并希望捕获[方括号]中的内容,除非它们用''[斜杠]转义。

RegexPal来了。

RegEx

(?:[^'']|^)'[([^']]*)']

测试样本以查看问题:

This is a [block], but as you can see it is trying to capture the preceeding character. 
You can '[escape] a block, but this creates '[problems] with [blocks] that are [stacked][back][to][back].

Javascript的正则表达式引擎不支持lookbacking。。

您可以使用此变通方法

(?:'s|^|'])'[('w+)(?='])

第1组在[] 中捕获您所需的数据

演示