【发布时间】:2011-09-09 23:20:15
【问题描述】:
我想匹配以下
- com.my.company.moduleA.MyClassName
- com.my.company.moduleB.MyClassName
- com.my.company.anythingElse.MyClassName
但不是以下
- com.my.company.核心.MyClassName
我目前的简单正则表达式模式是:
Pattern PATTERN_MODULE_NAME = Pattern.compile("com\\.my\\.company\\.(.*?)\\..*")
Matcher matcher = PATTERN_MODULE_NAME.matcher(className);
if (matcher.matches()) {
// will return the string inside the parentheses (.*?)
return matcher.group(1);
}
所以,基本上,我怎样才能匹配其他所有内容,但不是特定字符串,在我的情况下是字符串 core。
请分享您对如何在 Java 中实现这一点的想法?
谢谢!
【问题讨论】:
标签: java regex regex-negation