「Java入門」replaceAll()でマッチした文字を正規表現で置換するサンプル
Javaコード
package com.arkgame.demopro;
public class ReplaceAllDemo {
public static void main(String[] args) {
String orgStr = "iphone\\_%";
String targetOrg = orgStr.replaceAll("\\\\\\_\\%", "plus");
System.out.println("置換前 : " + orgStr);
System.out.println("置換後 : " + targetOrg);
}
}
結果
置換前 : iphone\_%
置換後 : iphoneplus