6

次の 2 つのテキストの引用符の間にあるものを取得するにはどうすればよいですか?

text_1 = r""" "Some text on \"two\" lines with a backslash escaped\\" \
     + "Another text on \"three\" lines" """

text_2 = r""" "Some text on \"two\" lines with a backslash escaped\\" + "Another text on \"three\" lines" """

私にとっての問題は、エスケープされている場合は引用符を無視する必要があることですが、バックスラッシュをエスケープする可能性があります。

以下のグループを取得したいと考えています。

[
    r'Some text on \"two\" lines with a backslash escaped\\',
    r'Another text on \"three\" lines'
]
4

4 に答える 4

1

二重引用符以外のすべてに一致:

import re
text = "Some text on \"two\" lines" + "Another text on \"three\" lines"
print re.findall(r'"([^"]*)"', text)

出力

['two', 'three']
于 2013-04-21T11:06:52.920 に答える