正则 函数
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: "城市维护建设税"; // 从头找到第一组汉字