我有一个字符串:
"Yes, We do. This is a complex issue that deserves more than a one word answer," Zuckerberg said. Pallone called the response "disappointing."
如果使用Python在引号之间删除点标记(。),最好的方法是什么? 预期的结果如下:
"Yes, We do This is a complex issue that deserves more than a one word answer," Zuckerberg said. Pallone called the response "disappointing"
谢谢
答案 0 :(得分:1)
您可以使用正则表达式(\"[\s\S]*?\")
捕获所有引号“...”并在循环中处理替换。首先替换.
并存储到newquote
。然后用新的引号替换旧引号。
import re;
s = '"Yes, We do. This is a complex issue that deserves more than a one word answer," Zuckerberg said. Pallone called the response "disappointing."';
pattern = re.compile(r'(\"[\s\S]*?\")');
for (quote) in re.findall(pattern, s):
newquote = quote.replace('.', '');
s = s.replace(quote, newquote);
print s;