I have a regex to extract numbers from a given string
import re
compiled_pattern = re.compile(r'\d+')
sample = "Hello world 32"
print(compiled_pattern.findall(sample))
output:
['32']
But is it possible to return 1 if there is a number in the string and 0 otherwise? Essentially 1 if there is a match for the pattern in the string and 0 otherwise. So in this case, the op should be 1. Any suggestions would be helpful
print (1 if compiled_pattern.search(sample) else 0)?