fork download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.util.regex.*;
  4.  
  5. class Main
  6. {
  7. static List<Pattern> patternList;
  8.  
  9. static List<Pattern> getPatterns()
  10. {
  11. if (patternList == null)
  12. {
  13. String[] regexes = { "(a(?:b|c)a)", "((?:a|b)ba)", "(ab(?:a|c))" };
  14. patternList = new ArrayList<Pattern>();
  15. for (String rgx : regexes)
  16. {
  17. patternList.add(Pattern.compile(rgx));
  18. }
  19. }
  20. return patternList;
  21. }
  22.  
  23.  
  24. public static void main (String[] args) throws Exception
  25. {
  26. Matcher m = Pattern.compile("dummy").matcher("dummy");
  27. String s;
  28. while ((s = r.readLine()) != null)
  29. {
  30. System.out.printf("%nInput: '%s'%n", s);
  31. for (Pattern p : getPatterns())
  32. {
  33. m.reset(s).usePattern(p);
  34. System.out.printf("%s : %b%n", p.pattern(), m.matches());
  35. }
  36. }
  37. }
  38. }
Success #stdin #stdout 0.07s 380160KB
stdin
aba
abc
stdout
Input: 'aba'
(a(?:b|c)a) : true
((?:a|b)ba) : true
(ab(?:a|c)) : true

Input: 'abc'
(a(?:b|c)a) : false
((?:a|b)ba) : false
(ab(?:a|c)) : true