Smack Alpha
Smack Alpha

Reputation: 1980

Remove certain word using regular expression

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'

Upvotes: 1

Views: 71

Answers (1)

Rakesh
Rakesh

Reputation: 82755

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

Upvotes: 3

Related Questions