I have a string which may contain \"title1\" twice in it.
e.g.
server/api/shows?title1=its always sunny in philadelphia&title1=breaking ba
You could perhaps make use of a negative lookahead:
title1(?!.*title1)
And replace with title2.
title2
See how it's working here.