An example of a method for extracting Numbers from Java regular expressions
- 2020-04-01 02:40:19
- OfStack
@Test
public void test33() {
String phoneString = " Ha ha ,13888889999";
//Extraction of digital
// 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("");
}
Extract zhang SAN and remove the number
@Test
public void test() {
//Extract and remove Numbers
String r_name3 = " Zhang SAN 13599998888 000000";
Pattern pattern = Pattern.compile("[\d]");
Matcher matcher = pattern.matcher(r_name3);
System.out.println(matcher.replaceAll("").trim());
}