- public static void main(String[] args) {
- String regEx1 = "[\\u4e00-\\u9fa5]";
- String str = "1 2fdAsz我是hhhZ大傻";
- String s1 = matchResult(Pattern.compile(regEx1), str);
- System.out.println(s1);
- }
- public static String matchResult(Pattern p, String str) {
- StringBuilder sb = new StringBuilder();
- Matcher m = p.matcher(str);
- while (m.find())
- for (int i = 0; i <= m.groupCount(); i++) {
- sb.append(m.group());
- }
- return sb.toString();
- }
复制代码 |