Python Regex that adds space after dot

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

How can I use re to write a regex in Python that finds the pattern:

dot "." followed directly by any char [a-zA-Z] (not space or digit)

and then add a space between the dot and the char?

i.e.

str="Thanks.Bob" newsttr="Thanks. Bob" 

Thanks in advance, Zvi

回答1:

re.sub(r'\.([a-zA-Z])', r'. \1', oldstr)



回答2:

re.sub('(?<=\.)(?=[a-zA-Z])', ' ', str) 


回答3:

Try

re.sub(r"\.([a-zA-Z])", ". \\1", "Thanks.Bob") 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!