直接上代码
public class TestRemoveUnChinese {
public static String removeUnChinese(String str) {
return str.replaceAll("[^u4E00-u9FA5]", "");
}
public static void main(String[] args) {
String str = "我*=+!@爱#$%^&*我的[{祖国】};?)";
System.out.println("原文:" + str);
String result = TestRemoveUnChinese.removeUnChinese(str);
System.out.println("结果:" + result);
}
}
打印结果:
原文:我*=+!@爱#$%^&*我的[{祖国】};?)
结果:我爱我的祖国



