Answers for "regex replace all string python"

21

python replace regex

import re
s = "Example String"
replaced = re.sub('[ES]', 'a', s)
print replaced 
# will print 'axample atring'
Posted by: Guest on March-13-2020
0

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
Posted by: Guest on May-18-2021

Python Answers by Framework

Browse Popular Code Answers by Language