Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のコードは、str を "testss" に設定します。
String str = "test".replaceAll("(.*)$","$1s");
次のコードは「tests」に設定します
String str = "test".replaceFirst("(.*)$","$1s");
両方の操作で同じ結果が得られると予想していました。replaceAll が文字列の末尾に余分な s を追加する理由を誰かが説明できますか?
これは、 が からの2 つの文字列と空の文字列 ("")"(.*)$"をキャプチャするためです。したがって、replaceAll は two を追加します。"test""test""s"
"(.*)$"
"test"
"s"