匹配前面没有美元符号的“IF”或“If”

问题描述 投票:0回答:1

只是不知道如何匹配 IF 和 If,但不知道 if 或前缀为 $ 的。

示例:

If True then // <- match 
    
IF True then // <- match 
    
if True then // <- don't match (lowercase i)
     
{SIF NOT DEFINED(SAAS)} // <- don't match (part of another word)
{$IFDEF DEBUG} // <- don't match (preceded with a $)

ChatGPT 建议:

\bIf\b(?!\$)

但是当之前有

$
时就不起作用了。

regex pcre
1个回答
0
投票

您不必在此处使用lookahead 或lookbehind,因为您只想将术语

If
IF
作为整个单词进行匹配。只需使用单词边界即可:

\bI[Ff]\b
© www.soinside.com 2019 - 2024. All rights reserved.