python replace matching string code example
Example 1: python regex substitute
import re
s = "Example String"
replaced = re.sub('[ES]', 'a', s)
print replaced
Example 2: replacing a value in string using aregular expression pyhton
import re
s = '[email protected] [email protected] [email protected]'
print(re.sub('[a-z]*@', 'ABC@', s))
# [email protected] [email protected] [email protected]
Example 3: python replace matching string
s = 'one two one two one'
# 1st argument: string to find
# 2nd argument: string to put in place
print(s.replace(' ', '-')) # one-two-one-two-one