字谜验证器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字谜验证器相关的知识,希望对你有一定的参考价值。

This is a snippet to validate anagrams of 'debit card'. It validates 'debit card' and 'bad credit'
  1. //regular expression
  2. String patternStr = "(?=.*d.*d)(?=.*e)(?=.*b)(?=.*i)(?=.*t)(?=.*\s)(?=.*c)(?=.*a)(?=.*r)^..........$";
  3. boolean b;
  4. Matcher matcher;
  5. Pattern pattern;
  6.  
  7. System.out.println("Regex pattern = "+patternStr);
  8. pattern = Pattern.compile(patternStr);//compiles the regex
  9.  
  10. //validates bad credit
  11. System.out.println("Validating: bad credit");
  12. matcher = pattern.matcher("bad credit");
  13. b = matcher.matches();
  14. if(b) System.out.println("bad credit: matched");
  15. else System.out.println("bad credit: not matched");
  16.  
  17. //validates debit card
  18. System.out.println("Validating: debit card");
  19. matcher = pattern.matcher("debit card");
  20. b = matcher.matches();
  21. if(b) System.out.println("debit card: matched");
  22. else System.out.println("debit card: not matched");

以上是关于字谜验证器的主要内容,如果未能解决你的问题,请参考以下文章

精心收集的 48 个 JavaScript 代码片段,仅需 30 秒就可理解!(转载)

字谜验证器

web代码片段

代码高尔夫:查找所有字谜

找出两个字符串输入是不是是字谜,忽略空格、标点符号和数字

Ruby - 字谜代码