fork download
  1. public class Main
  2. {
  3. public static void main(String[] args) throws Exception
  4. {
  5. String str = "abc /** hi \r\n hello */ bbc";
  6. String regex = "^(MAX|SUM|AVERAGE|MIN): (\\d+(\\.\\d+)?(, (?=.)|$))+$";
  7. String regex2 = "^(MAX|SUM|AVERAGE|MIN): (\\d+(\\.\\d+)?(, \\d+(\\.\\d+)?)*)$";
  8.  
  9. String[] trues = {"MIN: 123",
  10. "MIN: 123, 1.2",
  11. "MIN: 123, 1",
  12. "MAX: 12, 12.32, 54.3332"};
  13. String[] falses = {"Randomdata",
  14. "MIN: ",
  15. "MIN: 123,",
  16. "MIN: 123, ",
  17. "MIN: 123, 1.",
  18. "MIN: 123, .1",
  19. "MIN: 123, 1, .1"};
  20. System.out.println("Trues:");
  21. for (String s: trues)
  22. System.out.println(s.matches(regex));
  23. System.out.println("\nFalses:");
  24. for (String s: falses)
  25. System.out.println(s.matches(regex));
  26. System.out.println("\n\nTrues:");
  27. for (String s: trues)
  28. System.out.println(s.matches(regex2));
  29. System.out.println("\nFalses:");
  30. for (String s: falses)
  31. System.out.println(s.matches(regex2));
  32. }
  33. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Trues:
true
true
true
true

Falses:
false
false
false
false
false
false
false


Trues:
true
true
true
true

Falses:
false
false
false
false
false
false
false