用于检查字符串前的一两个或三个单词的负后视或调和模式

Negative lookbehind or tempered pattern for checking one two or three words before a string

我正在尝试编写一个代码来识别支持术语(即 'detect' 'evidence'),除非在 [=24= 之前有一个否定术语 最多 3 个词].

一些例子: "FISH tests did not detect BCL2 translocation" "FISH tests did not provide evidence of a BCL2 translocation"

我试过使用 lookbehind,但由于它需要精确的长度,我无法灵活地回顾 1-3 个单词。

我试过使用调和点,但它给出了任意数量的单词。

我目前的代码看起来只有 'support diagnosis' 项前的一​​个词。

grepl("(?<!\bnot\b\s|cannot\s|n't\s|\bno\b\s|negative\s)(reveal|seen|show|detect|demonstrate|confirm|identif|evidence|suggest|positive|observe)(?:(?!\bnot\b)(?!cannot)(?!n't)(?!\bno\b)(?!negative for)(?!, ).)*?(bcl-?2|14[q]?[;:]18)"), y, perl=TRUE,ignore.case = T)

lookbehind 在这种情况下没有帮助,您可以做的是系统地搜索否定词并使用 (*SKIP)(*FAIL) 最多三个词丢弃部分字符串:

(\bnot\b|\bcannot\b|n't\b)(?:\W++(?!(?1))\w+){0,3}(*SKIP)(*F)|\b(reveal|seen|show)\b(?!\snot\b)