我正在阅读一个来源的回复,这是一篇日志或一篇文章,我将html响应作为一个字符串,如下所示:
据一些人说,梦表达了“人格的深刻方面”(Foulkes 184),尽管其他人不同意。
我的目标是从给定的字符串中提取所有引号,并将它们保存到一个列表中。我的做法是:
[match.start() for m in re.Matches(inputString, "\"([^\"]*)\""))]不知怎么的,对我没什么用。我在这里有什么帮助吗?非常感谢。
发布于 2014-03-29 18:57:58
如果没有嵌套的引号:
re.findall(r'"([^"]*)"', inputString)演示:
>>> import re
>>> inputString = 'According to some, dreams express "profound aspects of personality" (Foulkes 184), though others disagree.'
>>> re.findall(r'"([^"]*)"', inputString)
['profound aspects of personality']发布于 2014-03-29 18:59:14
如果您的输入可以有如下所示:some "text \" and text" more,请使用这个
s = '''According to some, dreams express "profound aspects of personality" (Foulkes 184), though others disagree.'''
lst = re.findall(r'"(.*?)(?<!\\)"', s)
print lst使用(?<!\\)负查找,它正在检查"之前是否没有\
https://stackoverflow.com/questions/22735440
复制相似问题