簡體   English   中英

字符串:僅刪除引號后的數字

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM