import java.util.regex.Matcher; import java.util.regex.Pattern; public class ok { public static void main(String[] args) throws Throwable { String str="asdas[45]sd[77]f[123]fd[3d4]";
Pattern p = Pattern.compile("\\[(\\d+)\\]"); Matcher m = p.matcher(str); while(m.find()){ String str1 = m.group(1); System.out.println(Integer.parseInt(str1)+10); } } }
例asdas[45]sd[77]f[123]fd[3d4]
输出
55
87
133
import java.util.regex.Pattern;
public class ok {
public static void main(String[] args) throws Throwable {
String str="asdas[45]sd[77]f[123]fd[3d4]";
Pattern p = Pattern.compile("\\[(\\d+)\\]");
Matcher m = p.matcher(str);
while(m.find()){
String str1 = m.group(1);
System.out.println(Integer.parseInt(str1)+10);
}
}
}