我正在写一个正则表达式来匹配“japan”的每一个出现处,并用“Japan”替换它。为什么下面的工作不成功?而“日本”可以在一个句子中的任何地方出现多次。我想替换所有的事件用另一个替换所有出现的单词
public static void testRegex()
{
String input = "The nonprofit civic organization shall comply with all other requirements of section 561.422, japan laws, in obtaining the temporary permits authorized by this act.";
String regex = "japan";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
System.out.println(input.matches(regex));
System.out.println(input.replaceAll(regex, "Japan"));
}
当你运行这个时你会得到什么输出? –
什么在这里不起作用?你的replaceAll对我来说似乎很好。 –
正则表达式匹配评估为false。 – Phoenix