Created
May 6, 2026 02:33
-
-
Save bg1bgst333/2b8afb9d25f070d878e4df52285f5fde to your computer and use it in GitHub Desktop.
String.replaceFirst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // メインクラス | |
| public class MainClass{ | |
| // Javaのエントリポイント | |
| public static void main(String[] arg){ // mainメソッドの定義 | |
| // 文字列str1の定義. | |
| String str1 = "ABC.ABC:ABC!ABC"; | |
| // 正規表現にマッチする部分の置換.(最初の1つだけ.) | |
| String str2 = str1.replaceFirst("B\\w+", "XY"); // Bから始まり, その後に英数字が1文字以上続く. | |
| // 出力. | |
| System.out.println(str2); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment