I have to find only two digit numbers in this case 32, but it is matching and printing 323, 32222,
Code:
import re
s = """32 M 32 L 32 S 32 K 324 J 32555 A 32222 B 8888
32 small again 32 324 567 323 yes 32 else again not 323 32 32-123"""
pattern = "32" # Also tried with "32/s" but if 32 present at end it does not match and also tried with "32{2}" still not working
# As per below answers, i used pattern = "\\b32\\b"
# But it is also matching 32-123, in my case only 32 must be matched
result = re.findall(pattern, s)
print(result)
print(len(result))
Expected Output: ['32', '32', '32', '32', '32', '32', '32', '32'] # length is 8 because string s contains 8 times 32 digits 8