+ Start a Discussion
SivarajanSivarajan 

Regular Expression to find Chinese characters

Hi Folks,

If a string contains atleast one chinese character then i have return a boolean. I am looking for exact regular expression to use in pattern.matches method.

Any help much appreciated.
 
sandhya reddy 10sandhya reddy 10
hi Sivarajan,

Below code will help you.

public static Boolean containsChineseCharacters(String InputString)
{
Pattern p = Pattern.compile('\\p{IsHan}');
Matcher m = p.matcher( InputString );
return m.find();
}

Please let us know if this helps you.

Thanks and Regards
sandhya reddy
SivarajanSivarajan

Thanks for sharing. This pattern '\\p{IsHan' detects Japanese character as well. Is there way to check only Chinese characters. ? 
Seb OrtizSeb Ortiz
You need to check which writing system (script (https://en.wikipedia.org/wiki/Script_%28Unicode%29)) does Chinese language use, and then just use the script code in the regular expresion. Here is a list of Scripts codes supported by Unicode

https://www.regular-expressions.info/unicode.html

Regards