fork(4) download
  1. import java.util.regex.*;
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String test = "ABC-122-JDHFHG-456-MKJD";
  12.  
  13. Matcher m = Pattern.compile("(?=\\b([A-Z]+-[0-9]+-[A-Z]+)\\b)")
  14. .matcher(test);
  15. while (m.find()) {
  16. System.out.println(m.group(1));
  17. }
  18. }
  19. }
Success #stdin #stdout 0.04s 4575232KB
stdin
Standard input is empty
stdout
ABC-122-JDHFHG
JDHFHG-456-MKJD