简体   繁体   English

用于获取仅评估字符串一部分的行的正则表达式,java

[英]Regular expression to fetch lines evaluating only one part of a string, java

I'm trying to find the regular expression to match only a part of the pattern我试图找到正则表达式只匹配模式的一部分

For an example text is :例如文本是:

GoodClass.NiceMethod
BadClass.NiceMethod
Badclass2.NiceMethod
Verybadclass.NiceMethod
GoodClass.NiceMethod
BadClass.NiceMethod
Badclass2.NiceMethod
GoodClass.NiceMethod

how can I get all lines where 'NiceMethod' does not follow 'GoodClass'我怎样才能得到'NiceMethod'不遵循'GoodClass'的所有行

您可以使用负面回顾

String regex = "(?<!GoodClass\\.)\\bNiceMethod\\b";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM