简体   繁体   中英

replacing a sub string using regular expression in python

I have a string that contains sub strings like

           RTDEFINITION(55,4)         RTDEFINITION(45,2)

I need to replace every occurrence of this kind of string with another string:

          DEFRTE

using Python and regular expressions. Any ideas? thx

This should work

import re

re.sub(r'RTDEFINITION\(\d+,\d+\)', 'DEFRTE', mystring)

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