Home > Software engineering >  String: Only Remove Numbers Following a Quotation Mark
String: Only Remove Numbers Following a Quotation Mark

Time:09-28

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

CodePudding user response:

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
  • Related