简体   繁体   中英

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'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM