除正则表达式python外的所有内容

时间:2019-01-25 22:26:33

标签: python regex

嗨,我想选择除'。'之后的单词以外的所有单词。还有第一个字

我的字符串是这样的:

The Persian League is the largest sport event dedicated to the deprived areas of Iran. The Persian League promotes peace and friendship.This video was captured by one of our heroes who wishes peace."

和我的正则表达式,用于选择'。'之后的单词。第一个词是:

(^\w+ |\.\s*\w* )

我想要除此正则表达式外的所有单词。

1 个答案:

答案 0 :(得分:1)

使用re.replace()将与正则表达式匹配的所有内容替换为空字符串,以将其删除。

new_string = re.replace(r'(^\w+ |\.\s*\w* )', '', string);