How to use regular expressions to replace word in a string with Python

2 Answers

0 votes
import re

s = "python c++ c c# java sql"

s = re.sub('sql', 'php', s)

print(s)

'''
run:

python c++ c c# java php

'''

 



answered Feb 25, 2017 by avibootz
0 votes
import re

s = "python c++ c c# java python"

s = re.sub('python', 'php', s)

print(s)

'''
run:

php c++ c c# java php

'''

 



answered Feb 25, 2017 by avibootz
...