Who can help me to translate this XML Schema pattern "[0-9]+-([0-9]|K)" to java regular expression?
A:
Here is the pattern with a snippet on how to use it.
\\ is there to escape the \ in a string. \d represents [0-9]. I do not recall if the - has to be escaped so I did it just in case.
Pattern p = Pattern.compile("\\d+\\-[\\d|K]"); //The string is the pattern
Matcher m = p.matcher(whatYouWantToMatch);
boolean b = m.matches();
Lombo
2010-02-25 18:57:27
Thanks! I just find out that it is compatible... this worked fine: s.matches("[0-9]+-([0-9]|K)")
Geykel
2010-02-25 19:02:45
You forgot the | in [0-9]|K
Geykel
2010-02-25 19:04:08
there.15 chars!
Lombo
2010-02-25 19:24:29
now you got it ;) I used with your regex: s.matches("\\d+\\-[\\d|K]")
Geykel
2010-02-25 21:07:48
A:
At least this case is compatible with java regex...
String s = "test cases here";
s.matches("[0-9]+-([0-9]|K)") //works OK.
Geykel
2010-02-25 19:09:00