开发者

Translate XML Schema pattern to Java regular expression

开发者 https://www.devze.com 2022-12-21 02:02 出处:网络
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.

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

精彩评论

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

关注公众号