雪洗中关村

导航

正则 函数

 

 

public static String isContainType(String type, String str) {
        Pattern p = Pattern.compile(type);
        Matcher m = p.matcher(str);
        if (m.find()) {
            return m.group();
        }
        return null;
}
 
String containType = isContainType("[\\u4e00-\\u9fa5]+", "印花税-20181010-201810105.10城市维护建设税20180701-2018093013.82"); 
System.out.println(
"-38-->" + containType);//res: "印花税"; // 从头找到第一组汉字
String containType = isContainType("[\\u4e00-\\u9fa5]+", "-20181010-201810105.10城市维护建设税20180701-2018093013.82"); 
System.out.println("-39-->" + containType);//res: "
城市维护建设税"; // 从头找到第一组汉字
 

 

posted on 2018-12-27 10:50  雪洗中关村  阅读(167)  评论(0编辑  收藏  举报