gpt4 book ai didi

python - 正则表达式:在 python 中匹配句号和一个词

转载 作者:行者123 更新时间:2023-11-28 19:55:58 26 4
gpt4 key购买 nike

我是正则表达式的新手。我想写一个匹配 '.' 的正则表达式。后跟一个空格后跟一个单词(不包含空格。

例如,在字符串“The sound of cracking. Splintering. A shape appears, in ice.”中,正则表达式应该提取“.Splintering”和“.A”。

最佳答案

import re
input = 'The sound of cracking. Splintering. A shape appears, in ice.'
print re.findall("(\.\s+[a-zA-Z]+)", input)

输出:['。 split ','。 A']

关于python - 正则表达式:在 python 中匹配句号和一个词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22247359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com