[Solved] Regex replace `a.b` to `a. b`? [duplicate]


You can use the following ([abAB])\.([abAB])

>>> import re
>>> s = ['a.b', 'A.b', 'a.B', 'A.B']
>>> [re.sub(r'([abAB])\.([abAB])', r'\1. \2', i) for i in s]
['a. b', 'A. b', 'a. B', 'A. B']

The issue with your approach is that you are not saving capturing groups to use in the result of the substitution.

If you want this to work for the entire alphabet, you can use this:

>>> s="billy.bob"
>>> re.sub(r'([a-zA-Z])\.([a-zA-Z])', r'\1. \2', s)
'billy. bob'

2

solved Regex replace `a.b` to `a. b`? [duplicate]