以tr(“and end with”)开头的字符串的Python正则表达式

2024-09-24 22:21:01 发布

您现在位置:Python中文网/ 问答频道 /正文

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

例如

str = 'According to some, dreams express tr("profound aspects of personality")' and 'tr("Foulkes 184"), though others disagree.'

所以我想要弦乐“人格的深刻方面”和“福克斯184”

有人能帮我吗?在


Tags: andofto字符串sometrexpressstr
1条回答
网友
1楼 · 发布于 2024-09-24 22:21:01

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

> 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']

演示:https://regex101.com/r/xgG9AO/5

来自findall文档:

If one or more groups are present in the pattern, return a list of groups.

相关问题 更多 >