Regular Expressions Match Chinese

Source: Internet
Author: User

One:

Package Cn.sunzn.demo;import Java.util.regex.matcher;import Java.util.regex.pattern;public class Demo {public    static void Main (string[] args) {        System.out.println (Iscontainchinese ("China"));    public static Boolean Iscontainchinese (String str) {        Pattern p = pattern.compile ("[\u4e00-\u9fa5]");        Matcher m = p.matcher (str);        if (M.find ()) {            return true;        }        return false;    }}

Operation Result:

True

 

Two:

Package Com.renmai.test;import Java.util.regex.matcher;import Java.util.regex.pattern;import org.junit.Test;public Class Patterntest {@Testpublic void test2 () {Pattern pattern = Pattern.compile ("f (. +?) K "); Matcher Matcher = Pattern.matcher ("FCKFKKFKF"), while (Matcher.find ()) {String s0 = Matcher.group (); String S1 = matcher.group (1); System.out.println (S0 + "*******" + S1);} System.out.println ("---------------------------"); Matcher.reset ("fucking"); while (Matcher.find ()) { System.out.println (Matcher.group ());} Pattern pattern2 = Pattern.compile ("f (. +?)" I (. +?) H "); Matchermatcher2 = Pattern2.matcher ("Finishabigfishfrish"), while (Matcher2.find ()) {String s0 = Matcher2.group (); String S1 = matcher2.group (1); String s2 = matcher2.group (2); System.out.println (S0 + "*******" + S1 + "------" + s2);} System.out.println ("----------------------------------"); Pattern pattern3 = Pattern.compile ("19|20\\d\\d ([-/.]) (0[1-9]|1[012]) \\2 (0[1-9]|[ 12][0-9]|3[01]); Matcher Matcher3 = Pattern3.matcher ("1900-01-01 2007/08/13 1900.01.01 1900 1900-01.01 1900 "), while (1900 ()) {Matcher3.find (System.out.println R3.group ());}} @Testpublic void Test3 () {Pattern pattern = pattern.compile ("death | Most Beautiful | | String str = "Content needed to match"; Matcher Matcher = Pattern.matcher (str), while (Matcher.find ()) {System.out.println (Matcher.group ());}}}

Matching principle: Requires that matching rules use Unicode encoding

  

Regular Expressions Match Chinese

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.