![](/img/trans.png)
[英]How to remove specific character in string if it is in quotation mark Python
[英]String: Only Remove Numbers Following a Quotation Mark
我有一個類似於the "cow"1 jumped "over"2 the moon and the "spoon"3... this happened 123 times
我只想刪除引號后面的數字: the "cow" jumped "over" the moon and the "spoon"... this happened 123 times
嘗試這個:
請參閱此處的正則表達式模式。
import re
string = 'the "cow"1 jumped "over"2 the moon and the "spoon"3... this happened 123 times'
pat = r"(?<=\")(\d+)"
out = re.sub(pat, "", string)
print(out)
the "cow" jumped "over" the moon and the "spoon"... this happened 123 times
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.