fork(1) download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. class Ideone
  5. {
  6. public static boolean testString(String s) {
  7. String regex = "(\\d+)-(\\d+) (\\w): ([a-z]+)";
  8. Pattern pattern = Pattern.compile(regex);
  9. Matcher matcher = pattern.matcher(s);
  10.  
  11. matcher.find();
  12. //System.out.println("Full match: " + matcher.group(0));
  13.  
  14. Pattern p = Pattern.compile(matcher.group(3));
  15. Matcher m = p.matcher(matcher.group(4));
  16. long count = m.results().count();
  17. if(count < Long.parseLong(matcher.group(1)) || count > Long.parseLong(matcher.group(2))) {
  18. return false;
  19. } else {
  20. return true;
  21. }
  22. }
  23.  
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. final String string = "9-11 w: wwtxmsjwjwlw\n"
  27. + "5-6 g: wggghg\n"
  28. + "1-5 g: dxggdggb\n"
  29. + "5-13 f: lfgdplfffxffswck\n"
  30. + "6-7 z: zzzzgzzzz";
  31.  
  32. for (String s: string.split("\n")) {
  33. System.out.println(s);
  34. System.out.println(testString(s));
  35. }
  36. }
  37. }
Success #stdin #stdout 0.08s 34040KB
stdin
Standard input is empty
stdout
9-11 w: wwtxmsjwjwlw
false
5-6 g: wggghg
false
1-5 g: dxggdggb
true
5-13 f: lfgdplfffxffswck
true
6-7 z: zzzzgzzzz
false