日期:2014-05-20 浏览次数:20757 次
String string = "abc123df12gh630hh2";
Pattern p = Pattern.compile("\\d+");
Matcher m = p.matcher(string);
StringBuilder builder1 = new StringBuilder();
int index = 0;
while (m.find()) {
builder1.append(string.substring(index, m.start()));
builder1.append("*").append(m.group()).append("*");
index = m.end();
}
builder1.append(string.substring(index));
System.out.println(builder1.toString());
public static void main(String[] args) throws Exception{
String src="abc123df12gh630hh2";
src=src.replaceAll("(\\d+)","*$1*");
System.out.println(src);
}