re python - 提取字符串

时间:2018-05-11 19:14:28

标签: python regex

我试图删除某个字符串的某个部分,但目前没有得到正确的答案。字符串是:

new_text = "'Bob' is currently 'Absent'. Hi, my name is Matt. 'Bob' is currently 'Active'. Bob: Hey Matt"

我希望两个子字符串:'Bob' is currently 'Absent'.'Bob' is currently 'Active'.消失。名字" Bob"可以在具有字母和非字母字符的名称之间切换。 "缺席"和"活跃"是显示的两种更常见的状态,但是,我想跟踪单引号内的任何字符串。

这是我想要返回的最后一句话:Hi, my name is Matt. Bob: Hey Matt

目前我的代码是:

re.sub(r"\'([\w\W\d]+)\' is currently \'[\w\W\d]+\'.\s", '', new_text)

它回来了:Bob: Hey Matt

任何人都可以帮忙吗?

0 个答案:

没有答案