fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. String ok_pattern = "(?:itId=<(\\d+)>) Code < |\\G(?!^)\\[OK:([^]]+)\\]\\s*";
  15. Pattern p_ok = Pattern.compile(ok_pattern);
  16. String testString = "RANDOMTEXT itId=<1232> Code < [OK:AZ1000105] [OK:10000006] [OK:F1000000007] > RANDOMTEXT";
  17. Matcher m = p_ok.matcher(testString);
  18.  
  19. while(m.find()) {
  20. if (null != m.group(1)) {
  21. System.out.println("itId: " + m.group(1));
  22. }
  23. if (null != m.group(2)) {
  24. System.out.println("Ok code: " + m.group(2));
  25. }
  26.  
  27. }
  28. }
  29. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
itId: 1232
Ok code: AZ1000105
Ok code: 10000006
Ok code: F1000000007