FranAguiar
FranAguiar

Reputation: 647

CJK characters detection issue

I want to detect any asian character, my code works in most of the cases, but not for Korean, I can't detect when a String has a Korean character.

This is my code:

Pattern pattern = Pattern.compile("\\p{InHiragana}|\\p{InKatakana}|\\p{IsHan}|\\p{IsHangul}}", Pattern.UNICODE_CASE);
System.out.println(pattern.matcher("성동구").find()); //return false

I tried whit "InCJK_Compatibility, InCJK_Unified_Ideographs, InCJK_Compatibility_Forms" and other CJK groups, no one works

Fixed code:

Pattern pattern = Pattern.compile("\\p{InHiragana}|\\p{InKatakana}|\\p{IsHan}|\\p{IsHangul}", Pattern.UNICODE_CASE);
System.out.println(pattern.matcher("성동구").find()); //return true

Upvotes: 0

Views: 422

Answers (1)

Coder ACJHP
Coder ACJHP

Reputation: 2224

Try this way, it worked for me :

public class MatcherMatch {

public static void main(String[] args) {
    Pattern pattern = Pattern.compile("\\p{IsHangul}");
    Matcher matcher  = pattern.matcher("김인재 한국어/조선말");
    while(matcher.find()) {
        System.out.println(matcher.group());
    }
}

screenshot : enter image description here

Upvotes: 1

Related Questions