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