You can reference a Unicode block or a script for that.
Here's an example with a script:
Pattern p = Pattern.compile("\\p{IsHangul}");
Matcher m = p.matcher("김인재");
while (m.find()) {
System.out.println("Found: " + m.group());
}
Output
Found: 김
Found: 인
Found: 재
Notes
- For a reference on Unicode blocks, see here.
- For a reference on Korean machine characters see here.
- To validate a range of numbers of characters, use:
Pattern p = Pattern.compile("\\p{IsHangul}{min,max}");
wheremin
is your minimum size andmax
is your maximum size of Hangul characters. - The code you posted as a comment to your question will not work (although it will compile). Please find a reference on how to use Java
Pattern
s /Matcher
s here.
Caveat for legacy Android versions (9 or lower)