You can use positive look behind to ensure the matched text is preceded by application/ using this regex,
(?<=application/)[^/]+
Here, [^/]+ part will capture any text except /, giving you your desired text 1007
Regex Demo
Java code,
String s = "http://localhost:8080/api/rest/loan/application/1007/applicant/951/pan";
Pattern p = Pattern.compile("(?<=application/)[^/]+");
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group());
}
Prints,
1007
Another easier and more performant way to do the same task would be to use following grouping pattern,
/application/([^/]+)
and capture the contents of group1.
Regex Demo with grouping pattern
Notice, this is much faster as well as will work broadly as look arounds are sometimes not supported in some dialects.
Java code,
String s = "http://localhost:8080/api/rest/loan/application/1007/applicant/951/pan";
Pattern p = Pattern.compile("/application/([^/]+)");
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group(1));
}
Prints,
1007
substringandindexof. You could also treat the URL as aPath(definitely hackish and not the recommended usage) if you know the index of the element relative to the name count in advance.http://server.com/application/index.php?ord=asc&date=today#info? What is expected result if word would also beapplication?