def replaceNth(s, source, target, n):
    inds = [i for i in range(len(s) - len(source) + 1) if s[i:i + len(
        source)] == source]
if len(inds) < n:
    return
s = list(s)
s[inds[n - 1]:inds[n - 1] + len(source)] = target
return ''.join(s)
How to find and replace nth occurence of word in a sentence using python regular expression?