fork(2) 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. import java.util.ArrayList;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. String regex = "^\\d*::[a-zA-Z]+[^\\(]*\\(\\d{4}\\)::(?<disease>(?:HIV|Cancer|flu|Arthritis|OCD)(?:\\|(?:HIV|Cancer|flu|Arthritis|OCD))*)$";
  16. String string = "24::Robin (1980)::HIV|Cancer|Cancer|HIV";
  17.  
  18. Pattern pattern = Pattern.compile(regex);
  19. Matcher matcher = pattern.matcher(string);
  20.  
  21. if (matcher.find()) {
  22. String[] parts = matcher.group("disease").split("\\|");
  23. Set<String> uniqueDiseases = new HashSet<String>(Arrays.asList(parts));
  24. System.out.println(uniqueDiseases);
  25. }
  26. }
  27. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
[HIV, Cancer]