I have this situation where i have a string of which i have to replace certain parts. I know where these parts are and what they look like (in other words i can match them through a regex) but not only i don't know the exact content but there might be similar substrings inside a string. What i want to achieve is to replace only the particular occurrence at that offset while leaving the rest intact.
An Example:
Test String (this) Test (not this) Test Test (this) Test Test (and this) Test (this maybe)
I know i have to replace strings that match this regex: \(.*?\)
but only if they start in positions 12, 62 and 78
(in other words, the first (this)
but not the second, (and this)
and (this maybe)
. the substrings (not this)
and the second (this)
must not be replaced)
I know i should be posting my attempts at the problem but i'm staring at the code since half an hour and no idea came out of it (i've been staring at code for longer time before giving up and ask in the past, but today i'm a bit in a hurry) but i have this feeling the solution is simpler than i think. The only thing i have realized is that i should replace strings in reverse order so i don't modify the positions