fork download
  1. /* package whatever; // don't place package name! */
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import java.util.regex.Pattern;
  5. import java.util.regex.Matcher;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class RoundhouseKick9
  9. {
  10. public static void main (String[] args) throws java.lang.Exception{
  11. List<String> Regex = new ArrayList<String>();
  12. Regex.add("hello"); // a
  13. Regex.add("[^0-9A-Z]$") ; // b
  14. Regex.add("\\w\\w\\w\\w\\w"); // c
  15. Regex.add("\\w\\w"); // d
  16. Regex.add("^\\w* \\w*$"); // e
  17. Regex.add("^\\w* \\w*!$"); // f
  18. Regex.add("^\\w* [\\w!]*$"); // g
  19. Regex.add("\\w{5} \\w+"); // h
  20. Regex.add("\\w{5} \\w+$"); // i
  21. for (String reg : Regex) {
  22. boolean b1 = Pattern.matches(reg, "Hello World");
  23. boolean b2 = Pattern.matches(reg, "What do we say to PABS? - Not today!");
  24. System.out.print(b1); System.out.print(", "); System.out.println(b2);
  25. }
  26. }
  27. }
  28.  
Success #stdin #stdout 0.06s 28128KB
stdin
Standard input is empty
stdout
false, false
false, false
false, false
false, false
true, false
false, false
true, false
true, false
true, false