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.
请在这里帮助我
对于下面的示例,我如何编写正则表达式来查找以 ABC 开头而不以 XYZ 结尾的字符串
例子:
ABCfdsAFfadsXYZ ABCffasdffdaAAA FASfdaaffasaAFA
其中,只有第二个应该匹配。
\bABC\w*\b(?<!XYZ)
假设您的正则表达式引擎支持后向断言。
解释:
\b # Start at a word boundary ABC # Match ABC \w* # Match any number of alphanumeric characters \b # End at a word boundary (?<!XYZ) # Assert that the previous three characters were not XYZ