代码如下:
@Test
public void test33() {
String phoneString = "哈哈,13888889999";
// 提取数字
// 1
Pattern pattern = Pattern.compile("[^0-9]");
Matcher matcher = pattern.matcher(phoneString);
String all = matcher.replaceAll("");
System.out.println("phone:" + all);
// 2
Pattern.compile("[^0-9]").matcher(phoneString).replaceAll("");
}
提取张三,去除数字
复制代码代码如下:
@Test
public void test() {
// 提取张三 去除数字
String r_name3 = "张三 13599998888 000000";
Pattern pattern = Pattern.compile("[\\d]");
Matcher matcher = pattern.matcher(r_name3);
System.out.println(matcher.replaceAll("").trim());
}