I am a bit new to regex. I want to convert examples such as
hello coffee 0 .08 - 0 .24% to
hello coffee 0.08 - 0.24% (removal of space before decimal and ignore other situations). Can you please suggest a regex.
import re my_str = 'hello coffee 0 .08 - 0 .24%' my_str = re.sub(r'(d)s+([.]d)', '\1\2', my_str) print(my_str) # hello coffee 0.08 - 0.24%