How to replace matches of regular expression in a string using Python

1 Answer

0 votes
import re

s = "c++ yes python yes java Yes"

result = re.sub("[yY]es", "maybe", s)

print(result)


'''
run:

c++ maybe python maybe java maybe

'''

 



answered Jan 15, 2018 by avibootz
...