check if String contains Chinese by regex - Java Internationalization

Java examples for Internationalization:Charset

Description

check if String contains Chinese by regex

Demo Code


//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String text = "java2s.com";
        System.out.println(containChinese(text));
    }/*  w  w  w.java 2  s  .  c  om*/

    private static final Pattern ChineseCharPatt = Pattern
            .compile("[\u4e00-\u9fa5]");

    public static boolean containChinese(String text) {
        Matcher m = ChineseCharPatt.matcher(text);
        if (m.find())
            return true;
        return false;
    }
}

Related Tutorials