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);
    }
}

猜你喜欢

转载自www.cnblogs.com/it-mh/p/10556555.html
今日推荐