Java regular expression Match Group
public static List splitExpr(String exp){
List list = new ArrayList();
StringTokenizer stoken = new StringTokenizer(exp, "+-/* ", true);
while(stoken.hasMoreTokens()){
String token = stoken.nextToken();
list.add(token);
}
return list;
}
String pattern = "([a-z]+).([a-zA-Z-]+)(/)";
String[] strArr = {
"www.google.com/search?q=goog/nice",
"http://www.google.msn.ca/a/b/c/d"
};
Pattern r = Pattern.compile(pattern);
for(int i=0; i < strArr.length; i++) {
Matcher mat = r.matcher(strArr[i]);
if(mat.find()) {
System.out.println("Found value: " + mat.group(1) );
}
}
}