Python Regex to add space after dot or comma

后端 未结 2 1885
你的背包
你的背包 2021-01-06 10:47

I have a string as follows:

line = \"This is a text.This is another text,it has no space after the comma.\"

I want to add a space after dots and

2条回答
  •  耶瑟儿~
    2021-01-06 11:06

    alternatively your can also be solved without regex as follow :

    >>> line = "This is a text.This is another text,it has no space after the comma."
    >>> line.replace('.', '. ', line.count('.')).replace(',', ', ', line.count(','))
    'This is a text. This is another text, it has no space after the comma. '
    >>> 
    

提交回复
热议问题