我正在寫一個正則表達式來匹配「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