Replacing specific words in a string (Python)

后端 未结 3 781
你的背包
你的背包 2020-11-29 10:48

I would like to replace words in a string sentence such as:

What $noun$ is $verb$?

What\'s the regular expression to replace the characters

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 11:06

    In [1]: import re
    
    In [2]: re.sub('\$noun\$', 'the heck', 'What $noun$ is $verb$?')
    Out[2]: 'What the heck is $verb$?'
    

提交回复
热议问题