2012-09-29 59 views
1
没有结束

请帮我在这里正则表达式查找字符串与ABC开始,与XYZ

例如下面我怎么写正则表达式来查找与ABC开始字符串,并与XYZ

没有结束

例:

ABCfdsAFfadsXYZ ABCffasdffdaAAA FASfdaaffasaAFA 

其中,只有第二个应该匹配。

+0

嗨史密斯和欢迎。对于标签[标签:正则表达式]来说并没有那么糟糕,但请告诉我们下次你尝试过什么。 –

回答

3
\bABC\w*\b(?<!XYZ) 

假设您的正则表达式引擎支持lookbehind断言。

说明:

\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 
+0

http://regexr.com?32abc :) – t3hn00b

+0

的确如此。 :)一切都很好,不是吗? –

+0

感谢Pietzcker ......它工作完美。 – Smith

相关问题