2017-02-16 6 views
1

私はtr( "")で囲まれたすべての文字列を与える正規表現をPythonで書いてみたいと思います。例えばtr( "で終わる")で始まる文字列のPython正規表現

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

は、だから私は、誰もこれで私を助けることができる文字列 "深遠な人格の側面" と "Foulkes 184"

をしたいですか?

答えて

4

んが先に必要な/ルックの背後には、re.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ドキュメントからhttps://regex101.com/r/xgG9AO/5

場合は、1つ以上のグループをパターンに存在する場合は、グループのリストを返します。

+0

はいその作業:)。 –

関連する問題