简体   繁体   English

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

[英]Regex: match fullstop and one word in python

I am new to regex. 我是正则表达式的新手。 I wish to write a regex which matches a '.' 我希望编写一个与“。”匹配的正则表达式 followed by a whitespace followed by a word(which does not contain whitespace. 后面跟一个空格,后面跟一个单词(不包含空格。

For example, in the string "The sound of cracking. Splintering. A shape appears, in ice.", the regex should extract ". Splintering" and ". A". 例如,在字符串“破裂声。裂片。在冰中出现形状。”中,正则表达式应提取“。裂片”和“ .A”。

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

Output: ['. Splintering', '. A'] 输出: ['. Splintering', '. A'] ['. Splintering', '. A']

Try: 尝试:

(\.\s\w+)

Matches: 火柴:

. Splintering 分裂

. A 一种

See it in action. 看到它在行动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM