Skip to content

Instantly share code, notes, and snippets.

@bg1bgst333
Created May 6, 2026 02:33
Show Gist options
  • Select an option

  • Save bg1bgst333/2b8afb9d25f070d878e4df52285f5fde to your computer and use it in GitHub Desktop.

Select an option

Save bg1bgst333/2b8afb9d25f070d878e4df52285f5fde to your computer and use it in GitHub Desktop.
String.replaceFirst
// メインクラス
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