views:

121

answers:

2

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
Thanks! I just find out that it is compatible... this worked fine: s.matches("[0-9]+-([0-9]|K)")
Geykel
You forgot the | in [0-9]|K
Geykel
there.15 chars!
Lombo
now you got it ;) I used with your regex: s.matches("\\d+\\-[\\d|K]")
Geykel
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