I have this string:
file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/
My goal is to parse only the string AAA in this case, but I will face othere similar strings where AAA is not the string, but something different. Is there a way to solve this based for example on the recurrent string webapproot?
Use the Pattern
class using regex to extract the AAA
String s = "file:/C:/workWaveMaker/projects/AAA/webapproot/WEB-INF/classes/custom/";
Pattern p = Pattern.compile("/projects/(.*?)/webapproot/");
Matcher m = p.matcher(s);
if (m.find())
System.out.println(m.group(1)); // => result "AAA"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.