I am implementing RESTful query with JPA specification. Would like to handle url with multiple criteria that looks like this:
http://localhost:8080/samples?search=lastName:doe,age>25
The search string would match pattern (\\w+?)(:|<|>)(\\w+?) separated by ",".
Therefore, I wrote the following code to obtain Matcher from a string:
static Matcher getMatcherFromString(String str) {
Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),");
Matcher matcher = pattern.matcher(str + ",");
return matcher;
}
This method is then called in controller to parse the url.
However, when I tested the method with string analysisId:fdebfd6e-d046-4192-8b97-ac9f65dc2009, it returns null. Why did I do wrong for the pattern matching?
\wdoes not match-\wis for words. What should I use instead?[0-9a-zA-Z_-]?[\w-]([a-zA-Z_-])(:|<|>)([0-9a-zA-Z_-])and([\w-])(:|<|>)([\w-])and still does not work. I think the individual pattern is fine. It is the matcher groups that is not working.