@Testpublic void test() {String phoneString = "哈哈,13888889999";// 提取数字// 1Pattern pattern = pile("[^0-9]");Matcher matcher = pattern.matcher(phoneString);String all = matcher.replaceAll("");System.out.println("phone:" + all);// pile("[^0-9]").matcher(phoneString).replaceAll("");}
@Testpublic void test() {// 提取张三 去除数字String r_name3 = "张三 13599998888 000000";Pattern pattern = pile("[\\d]");Matcher matcher = pattern.matcher(r_name3);System.out.println(matcher.replaceAll("").trim());}
// 过滤除点号外的所有非数字String abc = "价格:0.00元";Pattern compile = pile("\\d+\\.\\d+");Matcher matcher = compile.matcher(abc);matcher.find();String string = matcher.group();//提取匹配到的结果System.out.println(string);//0.00
// 只要提取数字其它都不需要String abc = "手机:1319999999"; System.out.println(abc.replaceAll("\\D", ""));//1319999999
// 提取价格import java.util.regex.Matcher;import java.util.regex.Pattern;import org.junit.Test;public class test_money {@Testpublic void test(){//0//0.1//24.13String moneyString="1";Double extract_cost = extract_cost_dot(moneyString);System.out.println("extract_cost:"+extract_cost);}/*** 提取金额,规则为只提取数字和点号,必须有点号* 格式可以为0.0或者,11* @param cost* @return*/public Double extract_cost_dot(String cost) {Pattern compile = pile("(\\d+\\.\\d+)|(\\d+)");Matcher matcher = compile.matcher(cost);matcher.find();return Double.valueOf(matcher.group());}}