fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class Main
  5. {
  6. static void printMatch(String regex, String str, int... groups)
  7. {
  8. System.out.println("String = " + str);
  9. System.out.println("Regex = " + regex);
  10. Pattern p = Pattern.compile(regex);
  11. Matcher m = p.matcher(str);
  12. while (m.find())
  13. for (int i: groups)
  14. System.out.println("Group " + i + " = " + m.group(i));
  15. System.out.println();
  16. }
  17.  
  18. public static void main(String[] args)
  19. {
  20. String str = "|1 Style Indented Normal + Courier New T201_LLR_001|2 Style Indented Normal + Courier New Shall accept the three pointers.|3 Style Indented Normal + Courier New SSC_01_SRS_0001";
  21. String regex = "([^_\\s]+_LLR_\\d+)[^\\t]*\\t([^|]*)[^\\t]*\\t(SSC_.+)";
  22. printMatch(regex, str, 1, 2, 3);
  23. }
  24. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
String = |1 Style Indented Normal + Courier New    T201_LLR_001|2 Style Indented Normal + Courier New	Shall accept the three pointers.|3 Style Indented Normal + Courier New	SSC_01_SRS_0001
Regex = ([^_\s]+_LLR_\d+)[^\t]*\t([^|]*)[^\t]*\t(SSC_.+)
Group 1 = T201_LLR_001
Group 2 = Shall accept the three pointers.
Group 3 = SSC_01_SRS_0001