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.  
  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.  
  16.  
  17. final String regex = "^(?!(?:(?:(?:\\d{1,3}(?:[FM])\\.(?:Front|Profile|Right)\\.(?:Anger|Fear|Frown|Smile)\\.(?:BW\\.Micro|BW|C\\.Micro|C)))|(?:\\d{1,3}(?:F|M)\\.(?:Front|Profile|Right)\\.(?:Neutral|Smile)\\.(?:C\\.Micro|C|BW\\.Micro|BW|HighLight|LowLight|MedLight)\\.(?:BW\\.Micro|BW|C\\.Micro|C))|(?:\\d{1,3}(?:F|M)\\.(?:Selfie1|Selfie2|StudentID)\\.(?:C\\.Micro|C|BW\\.Micro|BW)))).*$";
  18. final String string = "95F Front Anger BW\n"
  19. + "95F Front Anger BW\n"
  20. + "95F Front Anger.BW\n"
  21. + "95F.Front.Anger.C.Micro\n"
  22. + "95F.Front.Fear.C.Micro\n"
  23. + "95F.Front.Frown.BW\n"
  24. + "-95F Front Anger BW.jpg \n"
  25. + "-95F.Front.Anger.C.Micro.jpg \n"
  26. + "-95F.Front.Fear.C.Micro.jpg \n"
  27. + "-95F.Front.Frown.BW.jpg";
  28.  
  29. final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
  30. final Matcher matcher = pattern.matcher(string);
  31.  
  32. while (matcher.find()) {
  33. System.out.println("Full match: " + matcher.group(0));
  34. for (int i = 1; i <= matcher.groupCount(); i++) {
  35. System.out.println("Group " + i + ": " + matcher.group(i));
  36. }
  37. }
  38.  
  39.  
  40.  
  41. }
  42. }
Success #stdin #stdout 0.1s 36584KB
stdin
Standard input is empty
stdout
Full match: 95F    Front   Anger   BW
Full match: 95F Front Anger BW
Full match: 95F Front Anger.BW
Full match: -95F Front Anger BW.jpg    
Full match: -95F.Front.Anger.C.Micro.jpg    
Full match: -95F.Front.Fear.C.Micro.jpg    
Full match: -95F.Front.Frown.BW.jpg