Replace all except the first occurrence of a substring in Python?

Published: 13/10/2019
Replace all except the first occurrence of a substring in Python?
Source: STACKOVERFLOW.COM

I have a string which looks like below string = "SELECT sdfdsf SELECT sdrrr SELECT 5445ff" Now I want to replace every occurrence of SELECT except the first one with @@@SELECT so that in the end string looks like this "SELECT sdfdsf @@@SELECT sdrrr @@@SELECT 5445ff" Now Python replace() replaces all occurrence of SELECT. string = string.replace("SELECT", "@@@SELECT) So the string becomes "

Read more
Related news
Comment
FACEBOOK