1

I have a string which is shown below:

a = 'steven (0.00030s ). prince (0.00040s ). kavin (0.000330s ). 23.24.21'

I want to remove the numbers inside () and the brackets and want to have it like this:

a = 'steven  prince  kavin  23.24.21'
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Smack Alpha
  • 1,828
  • 1
  • 17
  • 37
  • https://docs.python.org/3.4/howto/regex.html you can certainly find the answer there :) – Jim Eisenberg May 21 '19 at 12:45
  • Does this answer your question? [How can I remove text within parentheses with a regex?](https://stackoverflow.com/questions/640001/how-can-i-remove-text-within-parentheses-with-a-regex) – Tomerikoo Apr 06 '21 at 12:02

1 Answers1

3

Use re.sub

Ex:

import re
a = 'steven (0.00030s ). prince (0.00040s ). kavin (0.000330s ). 23.24.21'
print(re.sub(r"(\(.*?\)\.)", "", a))

Output:

steven  prince  kavin  23.24.21
Rakesh
  • 81,458
  • 17
  • 76
  • 113