如何使用replaceAll()更改字符串的子字符串 例如使用正则表达式“1 [a-z] +”(用“X”拆分)和代码:
"this is an example 1one"
应该产生:
"this is an example 1Xone"
答案 0 :(得分:1)
试试这个:
class Test {
public static void main(String[] args) {
String str = "this is an example 1one";
str = str.replaceAll("1([a-z]+)", "1X$1");
System.out.println(str);
}
}