简体   繁体   中英

Translate XML Schema pattern to Java regular expression

谁能帮助我将此XML模式模式“ [0-9] +-([0-9] | K)”转换为Java正则表达式?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM