The (?<!PAYROLL)
negative lookbehind matches a location that is not immediately preceded with PAYROLL
char sequence. In the PAYROLL FIDELITY
string, the FIDELITY
is not immediately preceded with PAYROLL
, it is immediately preceded with PAYROLL
+ space.
You can solve the current problem in various ways. If you are sure there is always a single whitespace between words in the string (say, it is a tokenized string) add s
after PAYROLL
: (?<!PAYROLLs)
.
If there can be one or more whitespaces, the (?<!PAYROLLs+)
pattern won't work in PCRE as PCRE lookbehind patterns must be of fixed width. You might match (some) exceptions and skip them using (*SKIP)(*FAIL)
PCRE verbs:
PAYROLLs+FIDELITY(*SKIP)(*F)|(FIDELITY(?!.*TITLE)(?!.*NATION)|INVEST)(?!.*PAYROLL)
See the regex demo. You may even replace PAYROLLs+FIDELITY(*SKIP)(*F)
with PAYROLL.*?FIDELITY(*SKIP)(*F)
or PAYROLL[sS]+?FIDELITY(*SKIP)(*F)
to skip any text chunk from PAYROLL
till the leftmost FIDELITY
. PAYROLLs+FIDELITY(*SKIP)(*F)
matches PAYROLL
, one or more whitespaces, FIDELITY
and then fails the match triggering backtracking, and then the match is skipped and the next match is searched for starting from the index where the failure occurred.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…