此问题与Match unless "escape" character is present非常相似,但已批准的解决方案并非在所有情况下都有效。
在我的场景中,我正在使用javascript并希望捕获[方括号]中的内容,除非它们用\ [斜杠]转义它。
正则表达式
(?:[^\\]|^)\[([^\]]*)\]
要测试的示例以查看问题:
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].
答案 0 :(得分:1)