62,614
社区成员
发帖
与我相关
我的任务
分享
public void test(){
String str = "I82+I88";
String regex = null;
String replacement = null;
str.replaceAll(regex, replacement);
//希望匹配后的结果,类似下面
str = "[T192.I82]+[T192.I88]";
}
public class Test {
public static void main(String[] args) {
String str = "I82+I88";
String regex = "(I\\d+)";
String replacement = "[T192.$1]";
str = str.replaceAll(regex, replacement);
System.out.println(str);
str = "[T192.I82]+[T192.I88]";
}
}
//满足str的匹配条件,regex和replacement如何写才正确
String str = "I82+I88";
String regex = "^[A-Z]{1-2}[0-9]{1-3}$";
String replacement = "[\0\1]";
Pattern pat = Pattern.compile(regex);
Matcher mat = pat.matcher(str);
boolean rs = mat.find();
if (rs) {
mat.replaceAll(replacement);
System.out.println(str);
}
String str = "I82+I88";
String regex = "([A-Z]{1,2}[1-9]{1,3})";
String replacement = "[T192\\.$1]";
System.out.println(str.replaceAll(regex, replacement));
// 希望匹配后的结果,类似下面
str = "[T192.I82]+[T192.I88]";
这样?