can only enter Chinese
/**
* 22. Verify Chinese character
* Expression ^[\u4e00-\u9fa5]{0,}$
* Describe only Chinese characters
* Matching example qingqing Moon * * *
@Test public
void A1 () {
Scanner sc = new Scanner (system.in);
String input = Sc.nextline ();
String regex = "^[\\u4e00-\\u9fa5]*$";
Matcher m = pattern.compile (regex). Matcher (input);
System.out.println (M.find ());
Sc.close ();
}
PS: The following Java to match the regular expression of Chinese can be written in two ways: first, the use of Unicode Chinese code, the second is the direct use of Chinese characters;
Cases:
(1) String str = "clear";
String regexstr = "[\u4e00-\u9fa5]";
Str.regex (REGEXSTR);
(2) String str = "clear";
String regexstr = "[A-龥]";
Str.regex (REGEXSTR);
Description
(1) Now most of the online to judge the Chinese character is \u4e00-\u9fa5 this range is just "China, Japan and South Korea unified Ideographic" This interval, but this is not all, if you want to include all, but also their extension set, radicals, pictographic words, note letters and so on; To view the Simplified Chinese encoding in Unicode
(2) "[A-龥]"; is the \u4e00-\u9fa5 corresponding Chinese. Specific Uniocde2 Chinese to query
The above is a small set of Java to introduce the use of regular expressions (regex) to match the Chinese instance code, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!