import re
passes = ['a1!','4B_','*x7']
fails = ['ab!','BBB','*x_','a1!B']
rx = re.compile(r"""
  (?!(?:[\W\d_]*[^\W\d_]){2})      # no two letters allowed
  (?!(?:\D*\d){2})                 # no two digits allowed
  (?!(?:[^_!@\#$*]*[_!@\#$*]){2})  # no two special chars allowed
  [\w!@\#$*]{3}                    # three allowed chars
  """, re.ASCII | re.VERBOSE)
for s in passes:
	print(s, ' should pass, result:', bool(rx.fullmatch(s)))
for s in fails:
	print(s, ' should fail, reuslt:', bool(rx.fullmatch(s)))