Trying to extract the id portion of the url string.
if(request.getPathInfo().matches("/products/(.*?)")) {
// use the id portion
// request.getPathInfo().split("/")[2] // simple attempt
} else if(request.getPathInfo().matches("/orders/(.*?)")) {
// use the id
}
Example string
/products/5d3abb1c30431b78fcf02290
/orders/5d3abb1c30431b78fcf01192
Edit
Attempt
Matcher m = Pattern.compile("/users/(.*?)").matcher(request.getPathInfo());
if(m.find()) {
System.out.println(m.group(0)); // /users/
System.out.println(m.group(1)); // empty string or null
} else {
System.out.println("not found");
}