I have a string /subscription/ffcc218c-985c-4ec8-82d7-751fdcac93f0/subscribe from which I want to extract the middle string /subscription/<....>/subscribe. I have written the below code to get the string
String subscriber = subscriberDestination.substring(1);
int startPos = subscriber.indexOf("/") + 2;
int destPos = startPos + subscriber.substring(startPos + 2).indexOf("/");
return subscriberDestination.substring(startPos, destPos + 2);
Gives back ffcc218c-985c-4ec8-82d7-751fdcac93f0
How can I use java Pattern library to write better code?
java Pattern library? Do you expect any performance gain? I doubt you'll get some by usingjava Pattern library. But I recommend to profile it to be absolute sure about it.