[Solved] regular expression to search only one-digit number


Use this pattern instead (it looks for single digits):

import re
print(re.search(r'\b\d\b', "I'm 30 years old."))

Output:

None

This also works for Unicode characters in Python 3. To also account for punctuation, you can use \b\d(\b|\.|\?|\!)

3

solved regular expression to search only one-digit number