My group could either be of the form x/y, x.y or x_y.z. Each group is separated by an underscore. The groups are unordered.
Example:
ABC/DEF_abc.def_PQR/STU_ghi_jkl.mno I would like to capture the following:
ABC/DEF abc.def PQR/STU ghi_jkl.mno I have done this using a fairly verbose string iteration and parsing method (shown below), but am wondering if a simple regex can accomplish this.
private static ArrayList<String> go(String s){ ArrayList<String> list = new ArrayList<String>(); boolean inSlash = false; int pos = 0 ; boolean inDot = false; for(int i = 0 ; i < s.length(); i++){ char c = s.charAt(i); switch (c) { case '/': inSlash = true; break; case '_': if(inSlash){ list.add(s.substring(pos,i)); inSlash = false; pos = i+1 ; } else if (inDot){ list.add(s.substring(pos,i)); inDot = false; pos = i+1; } break; case '.': inDot = true; break; default: break; } } list.add(s.substring(pos)); System.out.println(list); return list; }