How to use regular expressions to replace a word at end of a string in Python

1 Answer

0 votes
import re

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

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

print(s)

'''
run:

python c++ c c# java php

'''

 



answered Feb 25, 2017 by avibootz
...