开发者

Python Regex that adds space after dot

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="Than开发者_运维问答ks.Bob"
newsttr="Thanks. Bob"

Thanks in advance, Zvi


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


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


Try

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜