1

The regular expression is

String regex = "^[\\p{IsHangul}\\p{IsDigit}]+";

And whenever i do

text.matches(regex);

It works fine in my system but not in some of the system. I am not able to track the issue.

Thank you in advance.

Exception:

Exception in thread "main" java.util.regex.PatternSyntaxException: Unknown character property name {Hangul} near index 13
^[\p{IsHangul}\p{IsDigit}]+
             ^
       at java.util.regex.Pattern.error(Pattern.java:1713)
       at java.util.regex.Pattern.charPropertyNodeFor(Pattern.java:2437)
       at java.util.regex.Pattern.family(Pattern.java:2412)
       at java.util.regex.Pattern.range(Pattern.java:2335)
       at java.util.regex.Pattern.clazz(Pattern.java:2268)
       at java.util.regex.Pattern.sequence(Pattern.java:1818)
       at java.util.regex.Pattern.expr(Pattern.java:1752)
       at java.util.regex.Pattern.compile(Pattern.java:1460)
       at java.util.regex.Pattern.<init>(Pattern.java:1133)
       at java.util.regex.Pattern.compile(Pattern.java:823)
       at java.util.regex.Pattern.matches(Pattern.java:928)
       at java.lang.String.matches(String.java:2090)
       at com.mycompany.helper.ApplicationHelper.main(ApplicationHelper.java:200)
18
  • what is the error on other system? Commented Apr 21, 2014 at 11:55
  • Sorry, i have escaped { and } because for test. and "other system" means "different JVM". Commented Apr 21, 2014 at 11:56
  • the exception is "PatternSyntaxException" Commented Apr 21, 2014 at 11:56
  • if i validate it from "Pattern and Matcher" also same problem. Commented Apr 21, 2014 at 11:58
  • We need to see how you are using this regex in your other system. Post some example which reproduces your problem. Also posting stacktrace of thrown exception could be helpful with figuring out the problem. Commented Apr 21, 2014 at 11:59

2 Answers 2

2

According to Using Regular Expressions in Java:

Java 5 fixes some bugs and adds support for Unicode blocks. ...

Make sure you're using Java 5+ in the server.

Sign up to request clarification or add additional context in comments.

1 Comment

any way thanks. but the "IsHangul" will only work from java 1.7. Thank You.
1

It seems that Java version you are using is not able to recognise Hangul as correct script character so you can try to create your own character class which will cover same range as Hongul from newer versions of Java.

From what I see in code in source code of Character.UnicodeScript on Java 8 Hangul refers to Unicode ranges

  • 1100..11FF
  • 302E..302F
  • 3131..318F
  • 3200..321F
  • 3260..327E
  • A960..A97F
  • AC00..D7FB
  • FFA0..FFDF

so maybe try with such pattern

Pattern.compile("^["
        + "\u1100-\u11FF"
        + "\u302E-\u302F"
        + "\u3131-\u318F"
        + "\u3200-\u321F"
        + "\u3260-\u327E"
        + "\uA960-\uA97F"
        + "\uAC00-\uD7FB"
        + "\uFFA0-\uFFDF"
        + "\\p{IsDigit}]+");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.