I have a path /departments/{dept}/employees/{id}
. How do I obtain dept
and id
from path /departments/{dept}/employees/{id}
?
For example, I would like to obtain dept1
and id1
if path is /departments/dept1/employees/id1
I tried
String pattern1 = "departments/"
String pattern2 = "/employees"
Pattern p = Pattern.compile(Pattern.quote(pattern1) + "(.*?)" + Pattern.quote(pattern2));
Matcher m = p.matcher(text);
while (m.find()) {
String a = m.group(1);
}
Is there a simpler way to obtain dept1 and id1? I would prefer not using string.split as I have different paths for which I want to obtain path parameters and I prefer not having a dependency on the index position of the path parameters.