用[\\u4e00-\\u9fa5]就可以匹配汉字了。
代码如下:
import java.util.regex.Matcher;
import java.util.regex.Pattern;/**正则表达式匹配中文汉字*/
public class RegxChinese {
public static void main(String[] args) {
String s = "正则表#5~达@式324匹配中文sdf汉字";
regxChinese(s);
}
public static void regxChinese(String s) {
String reg_charset = "[\\u4e00-\\u9fa5]";
Pattern p = Pattern.compile(reg_charset);
Matcher m = p.matcher(s);
while(m.find()) {
System.out.println(m.group(0));
}
}
}