I'm trying to use a regular expression to match only odd numbers in a string. What I'm thinking is to detect whether the last digit of the number is odd or not, but now I can only find the first (n-1) digits except for the last one.
For example, the following code works for the odd number 13, which is perfect! But when it turns to 132, the code still returns 13, which definitely fails. So, how can I manipulate the code and let it work for all numbers (no matter how large it is) ending with odd digits? Thank you!
match= '(\s*\d*[13579]\s*)'
print(re.search(match, "The number 13 matches")) #<re.Match object; span=(10, 14), match=' 13 '>
print(re.search(match, "The number 132 matches")) #<re.Match object; span=(10, 13), match=' 13'>