Java regular judge whether a string contains Chinese

Using regular determines whether a string contains Chinese characters or Chinese

 

Code is implemented as follows:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Miracle Luna on 2019/12/20
 */
public class ChineseCheck {

    public static void main(String[] args) {
        Str String = "! The Hello" Azolla "" ;
        System.out.println("==> " + isContainChinese(str));
    }

    /**
     * String contains Chinese
     * @Param STR string to be verified
     * @Return to true false does not include Chinese characters include Chinese characters
      * / 
    public  static  boolean isContainChinese (String str) {

        Pattern p = Pattern.compile("[\u4E00-\u9FA5|\\!|\\,|\\。|\\(|\\)|\\《|\\》|\\“|\\”|\\?|\\:|\\;|\\【|\\】]");
        Matcher m = p.matcher(str);
        if (m.find()) {
            return true;
        }
        return false;
    }

}

 

Execution results are as follows:

==> true

 

Guess you like

Origin www.cnblogs.com/miracle-luna/p/12081811.html