I am trying to find the most efficient way natural to Python, to find all instances of a string within another string surrounded by a $$
sign and replace it with another value in another variable.
The string in question is like this "$$firstOccurance$$ some other words here then $$secondOccurance$$"
My solution below is not working, I think because it's not able to differentiate between the first time it finds the $$
sign and the second time it finds it again. This results in nothing getting printed. There can be many occurrences of strings between the $$
value.
the_long_string = "$$firstOccurance$$ some other words here then $$secondOccurance$$"
replacement_value = "someNewString"
print(the_long_string[the_long_string.index('$$')+len('$$'):the_long_string.index('$$')])
What would be the way to correct and fix what I have done so far?
The end result has to look like this someNewString some other words here then someNewString
, where there is no $$
sign left.