我正在寻找适用于以下结果的正则表达式:
字符串 = This is Cold Water and this is Hot Water, have some Water.
我想要检查这个字符串中是否有单词“Water”,并且该单词之前没有出现“Cold”和“Hot”这两个单词。
String mydata = "This is Cold Water and this is Hot Water, have some Water";
Pattern pattern = Pattern.compile("[^(Cold|Hot)]\sWater");
Matcher matcher = pattern.matcher(mydata);
if (matcher.matches()) {
String s = matcher.group(1);
System.out.println(s);
}
但是它导致了无匹配结果。