fork download
  1.  
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class Main
  6. {
  7. static void printMatch(String regex, String str, int... groups)
  8. {
  9. System.out.println("String = " + str);
  10. System.out.println("Regex = " + regex);
  11. Pattern p = Pattern.compile(regex);
  12. Matcher m = p.matcher(str);
  13. while (m.find())
  14. for (int i: groups)
  15. System.out.println("Group " + i + " = " + m.group(i));
  16. System.out.println();
  17. }
  18.  
  19. public static void main(String[] args)
  20. {
  21. printMatch("(?<=Hello:).*?(?=,|$)", "I am extracting this Hello:A;B;C, also Hello:D;E;F", 0);
  22. }
  23. }
  24.  
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
String = I am extracting this Hello:A;B;C, also Hello:D;E;F
Regex = (?<=Hello:).*?(?=,|$)
Group 0 = A;B;C
Group 0 = D;E;F