package com.zzk.cn;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TestString2 {
public static void main(String[] args) {
Pattern p = Pattern.compile("\\p{InCJK Unified Ideographs}.*(?=\u662f)");
String s = "\u5b81\u80d6\u7eb8\u662f\u6211\u7684\u540d\u5b57";
Matcher m = p.matcher(s);
while(m.find()) {
p(m.group());
}
}
public static void p(Object o) {
System.out.println(o);
}
}
package com.zzk.cn;
public class TestUnicode {
public static void main(String[] args) {
final String regex = "\\p{InCJK Unified Ideographs}(?<!\u662f)";
final String[] testChars = {
"\u5b81",
"\u80d6",
"\u7eb8",
"\u662f",
"\u6211",
"\u7684",
"\u540d",
"\u5b57"
};
String resultString="";
for (String s : testChars) {
resultString+=s;
System.out.printf("matched %s: %b\n", s, s.matches(regex));
}
System.out.println("你的名字是:"+resultString);
}
}