Translate XML Schema pattern to Java regular expression
Who can help me to translate t开发者_StackOverflow社区his XML Schema pattern "[0-9]+-([0-9]|K)" to java regular expression?
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();
At least this case is compatible with java regex...
String s = "test cases here";
s.matches("[0-9]+-([0-9]|K)") //works OK.
精彩评论