Depends on the exact structure of the strings you are trying to match; not everything is regular. A basic approach here would be:
private static final Pattern ACCOUNT_PROPERTIES =
Pattern.compile("/admin/account/bot/(\\d+)/layout/properties");
private static final Pattern BLOCK_CONTENT =
Pattern.compile("/admin/bot/(\\d+)/block/content/(\\w+)/(\\d+)/(\\w+)");
public void handle(String path) {
Matcher m;
m = ACCOUNT_PROPERTIES.matcher(path);
if (path.matches()) {
handlePropertiesUpdate(Integer.parseInt(m.group(1)));
return;
}
m = BLOCK_CONTENT.matcher(path);
if (path.matches()) {
int botId = Integer.parseInt(m.group(1));
String objType = m.group(2);
int objId = Integer.parseInt(m.group(3));
String updType = m.group(4);
handleBlockContent(botId, objType, objId, updType);
}
throw new NotAcceptedException();
}
etcetera.
Trying to make one regexp to catch it all seems... ill-advised. It'd be one heck of a job to try to figure out which group goes where, and an update in one of these structures would then neccessity updating all your code. There are ways to name groups, which is a slight improvement, but you're still looking at a gigantic regexp. If the aim is to 'make it run faster by running less code', I have bad news. Regexps make no guarantees about performance and have O(n^2) worst case if you use certain regex features. If you want speed, steer away from them, or at least be an expert so you know what and how to make them run quickly.