字符串的Python正则表达式,以tr开头(";并以";结尾)

字符串的Python正则表达式,以tr开头(";并以";结尾),python,regex,string,Python,Regex,String,我想用Python编写一个正则表达式,它将给出tr(“”)中包含的所有字符串 比如说, str = 'According to some, dreams express tr("profound aspects of personality")' and 'tr("Foulkes 184"), though others disagree.' 所以我想要弦乐《人格的深刻方面》和《福尔克斯184》 有人能帮我吗?不需要回头看,一个简单的小组就足够了: > s = 'According to

我想用Python编写一个正则表达式,它将给出tr(“”)中包含的所有字符串

比如说,

str = 'According to some, dreams express tr("profound aspects of personality")' and 'tr("Foulkes 184"), though others disagree.'
所以我想要弦乐《人格的深刻方面》和《福尔克斯184》


有人能帮我吗?

不需要回头看,一个简单的小组就足够了:

> s = 'According to some, dreams express tr("profound aspects of personality") "and" tr("Foulkes 184"), though others disagree.'
> re.findall(r'tr\("(.*?)"\)', s)
['profound aspects of personality', 'Foulkes 184']
演示:

findall
文档:

如果模式中存在一个或多个组,则返回组列表


不需要向后看/向前看,一个简单的小组就足够了:

> s = 'According to some, dreams express tr("profound aspects of personality") "and" tr("Foulkes 184"), though others disagree.'
> re.findall(r'tr\("(.*?)"\)', s)
['profound aspects of personality', 'Foulkes 184']
演示:

findall
文档:

如果模式中存在一个或多个组,则返回组列表