开发者

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜