I am trying to detect if a java string contains Japanese characters. Since it doesn't matter to me if the characters form a grammatically correct sentence, I thought that I would use a regular expression to match any Japanese character in a string like this:
package de.cg.javatest; import java.util.regex.Matcher; import java.util.regex.Pattern; public class JavaTest { public static void main(String[] args) { String aString = "γͺγ«γγͺγζ₯γ
γ"; Pattern pat = Pattern.compile("[\\p{InHiragana}]"); Matcher m = pat.matcher(aString); System.out.println(m.matches());
However, the print statement always shows false . I tried changing the template to
[\\p{IsHiragana}] [\\p{InHiragana}]+
and I also manually entered the codes. Is there something I donβt see, or do I need to take a different approach?
source share