I'm trying to use regular expressions to check if a string, str, contains at least two numbers and exactly two of any of the following symbols: '!','@','#','$','%','&','*'.
What seems to be happening is that I'm only matching if they occur consecutively and not in total. How do I fix this?
str = 'a1b2c$3d#4e!f@ghi0'
sym = '[!@#$%&*]{2}'
num = '[0-9]{2,}'
for char in str:
if re.search(sym, str):
if re.search(num, str):
print('match!')
else:
print('no matches!')