Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 Flex 中有这个正则表达式来查找每 2 个字母大写的单词:
[A-Z]{2} printf("Found %s", yytext);
但是我如何打印除 SN 之外的每个单词?
谢谢!!
您的正则表达式还将匹配子字符串,例如NA,SA当用于字符串时NASA。
NA
SA
NASA
您将需要使用单词边界来防止这种情况发生。然后,使用否定的前瞻断言来排除SN:
SN
\b(?!SN)[A-Z]{2}\b
编辑:哦,那个Flex :)
好吧,POSIX 正则表达式引擎不知道环视。你需要把它拼出来:
\b(S[A-MO-Z]|[A-RT-Z]N|[A-MO-RT-Z]{2})\b