String: Only Remove Numbers Following a Quotation Mark

Question:

I have a string similar to the "cow"1 jumped "over"2 the moon and the "spoon"3... this happened 123 times
I want to remove only the numbers following a quotation mark:
the "cow" jumped "over" the moon and the "spoon"... this happened 123 times

Asked By: timothy.s.lau

||

Answers:

Try this:

See the regex pattern here.

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
Answered By: Rabinzel
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.