fork download
  1. import re
  2. passes = ['a1!','4B_','*x7']
  3. fails = ['ab!','BBB','*x_','a1!B']
  4. rx = re.compile(r"""
  5. (?!(?:[\W\d_]*[^\W\d_]){2}) # no two letters allowed
  6. (?!(?:\D*\d){2}) # no two digits allowed
  7. (?!(?:[^_!@\#$*]*[_!@\#$*]){2}) # no two special chars allowed
  8. [\w!@\#$*]{3} # three allowed chars
  9. """, re.ASCII | re.VERBOSE)
  10. for s in passes:
  11. print(s, ' should pass, result:', bool(rx.fullmatch(s)))
  12. for s in fails:
  13. print(s, ' should fail, reuslt:', bool(rx.fullmatch(s)))
Success #stdin #stdout 0.02s 9520KB
stdin
Standard input is empty
stdout
a1!  should pass, result: True
4B_  should pass, result: True
*x7  should pass, result: True
ab!  should fail, reuslt: False
BBB  should fail, reuslt: False
*x_  should fail, reuslt: False
a1!B  should fail, reuslt: False