正则匹配并返回匹配结果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/XUEER88888888888888/article/details/86532938
 List<String> strs = new ArrayList<String>();
 Pattern p = Pattern.compile("\\d+,\\d+");
 Pattern p2 = Pattern.compile("\\d+");

                    Matcher m = p.matcher(ik);
                    while (m.find()) {
                        strs.add(m.group());
                    }



 String endDateNew = endDate.replaceAll("[\u4e00-\u9fa5]", ".");


 public static List<String> match(String s, String type) {

        //  String s = "ccc2016年08月-2018年07月的还款记录";
        List<String> strs = new ArrayList<String>();
        Pattern p = Pattern.compile("\\d+年\\d+月-\\d+年\\d+月的" + type);
        Matcher m = p.matcher(s);
        while (m.find()) {
            strs.add(m.group());
        }


        List<String> strs2 = new ArrayList<String>();
        String b = strs.get(0);
        Pattern pp = Pattern.compile("\\d+年\\d+");
        Matcher mm = pp.matcher(s);
        while (mm.find()) {

            strs2.add(mm.group().replaceAll("[\u4e00-\u9fa5]", "."));
        }


        return strs2;


    }

猜你喜欢

转载自blog.csdn.net/XUEER88888888888888/article/details/86532938