Kid*_*ddo 9 python regex string
我正在阅读来自日记或文章的来源的回复,我将html响应作为字符串,如:
根据一些人的说法,梦想表达了"人格的深刻方面"(Foulkes 184),尽管其他人不同意.
我的目标是从给定字符串中提取所有引号,并将每个引号保存到列表中.我的方法是:
[match.start() for m in re.Matches(inputString, "\"([^\"]*)\""))]
Run Code Online (Sandbox Code Playgroud)
不知怎的,它对我不起作用.我的正则表达式有什么帮助吗?非常感谢.
Mar*_*ers 22
如果没有嵌套引号:
re.findall(r'"([^"]*)"', inputString)
Run Code Online (Sandbox Code Playgroud)
演示:
>>> 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']
Run Code Online (Sandbox Code Playgroud)
如果您的输入可以具有以下内容,请使用此选项: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
Run Code Online (Sandbox Code Playgroud)
使用(?<!\\)负向后查找来检查\之前是否有"
| 归档时间: |
|
| 查看次数: |
20604 次 |
| 最近记录: |