Java——去除字符串中的中文

时间:2023-03-09 01:38:03
Java——去除字符串中的中文
import java.util.regex.Matcher;
import java.util.regex.Pattern; public class RemoveStrChinese {
private static String REGEX_CHINESE = "[\u4e00-\u9fa5]";// 中文正则 public static void main(String[] args) {
String str = "中文123中文qwer";
// 去除中文
// Pattern pat = Pattern.compile(REGEX_CHINESE);
// Matcher mat = pat.matcher(str);
// String string = mat.replaceAll(""); String string = str.replaceAll(REGEX_CHINESE, "");
System.out.println(string);
}
}