So I want to substitude dots in string when there is no space after of before the dots. I have thought this could be easily done with a regular expression but I haven't been able to do it.
I have patterns and I want them to be:
h.e.ll.o w.o.r.l.d
:hello world
h.e.ll.o w.o.r.l.d
:hello world
hello. world
:hello. world
I have tried the following patterns:
\w+(\.)+\w+
\w+(\.+\w+)
\w+\.+\w+
I always get something like: he.ll.o wo.rl.d
I am using python's re
module to match and replace with the following code:
>>> re.sub(r'\w+\.+\w+', lambda x: x.group(0).replace('.', ''), 'h.e.ll.o w.o.r.l.d')
'he.llo wo.rl.d'