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. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String regex = "^(?=.{3,15}$)[a-zA-Z]+[\\s'.a-zA-Z-]+[a-zA-Z]+$";
  14. String strings[] = {
  15. "f f f f f f f f",
  16. "fff fffffffffff",
  17. "fff ffffffffffff",
  18. "f f",
  19. "f"
  20.  
  21. };
  22.  
  23. Pattern pattern = Pattern.compile(regex);
  24. for (String s : strings) {
  25. Matcher matcher = pattern.matcher(s);
  26. if (matcher.find()) {
  27. System.out.println("Match: " + s);
  28. } else {
  29. System.out.println("No match: " + s);
  30. }
  31. }
  32. }
  33. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
Match: f f f f f f f f
Match: fff fffffffffff
No match: fff ffffffffffff
Match: f f
No match: f