Java pattern expression to exclude a special string
All , Source content may like this :
String content1 = "(\"../../aaa/bbb/ccc\")";
String content2 = "('/bb/add/www')";
String content3 = "(ggg/eee/xxx)";
String content4 = "('../../aaa/bbb/ccc')";
Who can help me design a high performance Java pattern matcher regex as
below:
regex = "^\\([\"\\'][(?:\\.\\.)?]([^\"\\)]+)[\"\\']\\)$";
public static String parsePath(String content,String regex) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
return matcher.group(1);
}
return null;
}
I want input such as content1 to content 4 , call parsePath function will
always return /aaa/bbb/ccc , /bb/add/www , /ggg/eee/xxx, /aaa/bbb/ccc .
So anyone who can help me to write a regex expression with high
performance ? Thank you !