如何排除特定的字符串常量? [英] How to exclude a specific string constant?
本文介绍了如何排除特定的字符串常量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用正则表达式来匹配除特定字符串常量(即 "ABC"
)以外的任何字符串?
Can regular expression be utilized to match any string except a specific string constant (i.e. "ABC"
)?
是否可以只排除一个特定的字符串常量?
Is it possible to exclude just one specific string constant?
推荐答案
你必须使用否定前瞻断言.
You have to use a negative lookahead assertion.
(?!^ABC$)
例如,您可以使用以下内容.
You could for example use the following.
(?!^ABC$)(^.*$)
如果这在您的编辑器中不起作用,请尝试此操作.经测试可在 ruby 和 javascript 中工作:
If this does not work in your editor, try this. It is tested to work in ruby and javascript:
^((?!ABC).)*$
这篇关于如何排除特定的字符串常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文