在引号前提取字符串
Extracting string before the quotations
我正在尝试解析 python 中的 pdf 并提取引号中的字符串。我能够提取引号中的文本,但我也想在引号开始之前提取名称。
例如:
考虑这个
齐布拉特,丹尼尔。 2004. "Rethinking the Origins of Federalism: Puzzle, Theory, and Evidence from Nineteenth-Century Europe,"
我可以提取所有引文,但我也想提取名称。
这是我正在使用的代码。请帮忙
def quotes(x):
quoted = re.compile('"[^"]*"')
for value in quoted.findall(x):
print value
在双引号之前捕获数据应该有效:
def quotes(x):
quoted = re.compile('(.+)"[^"]+"')
for value in quoted.findall(x):
print value.strip()
我得到这个输出:
>>> quotes(text)
'Ziblatt, Daniel. 2004.'
我正在尝试解析 python 中的 pdf 并提取引号中的字符串。我能够提取引号中的文本,但我也想在引号开始之前提取名称。 例如: 考虑这个
齐布拉特,丹尼尔。 2004. "Rethinking the Origins of Federalism: Puzzle, Theory, and Evidence from Nineteenth-Century Europe,"
我可以提取所有引文,但我也想提取名称。 这是我正在使用的代码。请帮忙
def quotes(x):
quoted = re.compile('"[^"]*"')
for value in quoted.findall(x):
print value
在双引号之前捕获数据应该有效:
def quotes(x):
quoted = re.compile('(.+)"[^"]+"')
for value in quoted.findall(x):
print value.strip()
我得到这个输出:
>>> quotes(text)
'Ziblatt, Daniel. 2004.'