62,623
社区成员
发帖
与我相关
我的任务
分享public class MyRegex {
public static void main(String[] args) {
String str="1-2$3";
str=str.replaceAll("\\D", "");//把不是数字的变成空
System.out.println(str);
}
}import java.util.regex.*;
public class MyRegex {
public static void main(String[] args) {
String str="1-2$3";
Matcher m=Pattern.compile("\\d").matcher(str);
String s="";
while(m.find())
s=s+m.group();
System.out.println(s);
}
}