[英]How to remove specific character in string if it is in quotation mark Python
我有一個字符串:
"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"
謝謝
您可以使用正則表達式(\\"[\\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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.