fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. List<String> strs = Arrays.asList("abc123#67812", "abc123%67812", "abc123#678120");
  11. String regexStr = "[^%\\s]{1,12}";
  12. Pattern pattern = Pattern.compile(regexStr);
  13.  
  14. for (String itemValue : strs) {
  15. Matcher matcher = pattern.matcher(itemValue);
  16. System.out.println("\"" + itemValue + "\": " + matcher.matches());
  17. }
  18. }
  19. }
Success #stdin #stdout 0.11s 50612KB
stdin
Standard input is empty
stdout
"abc123#67812": true
"abc123%67812": false
"abc123#678120": false