I'm trying regex after a long time. I'm not sure if the issue is with regex or the logic.
String test = "project/components/content;contentLabel|contentDec"; String regex = "(([A-Za-z0-9-/]*);([A-Za-z0-9]*))"; Map<Integer, String> matchingGroups = new HashMap<>(); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(test); //System.out.println("Input: " + test + "\n"); //System.out.println("Regex: " + regex + "\n"); //System.out.println("Matcher Count: " + matcher.groupCount() + "\n"); if (matcher != null && matcher.find()) { for (int i = 0; i < matcher.groupCount(); i++) { System.out.println(i + " -> " + matcher.group(i) + "\n"); } } I was expecting the above to give me the output as below:
0 -> project/components/content;contentLabel|contentDec 1 -> project/components/content 2 -> contentLabel|contentDec But when running the code the group extractions are off.
Any help would be really appreciated.
Thanks!
/