timothy.s.lau
timothy.s.lau

Reputation: 1101

String: Only Remove Numbers Following a Quotation Mark

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

Upvotes: 0

Views: 45

Answers (1)

Rabinzel
Rabinzel

Reputation: 7923

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

Upvotes: 3

Related Questions