@Anonymous , Welcome to Microsoft Q&A, you could try the following link to convert the Javascript to c#.
var ch = 'x';
var n = 3;
var str = "I amx nexver axt hoxme on Sxundxaxs";
var re = new Regex("((?:[^" + ch + "]*" + ch + "){" + (n - 1) + "}[^" + ch + "]*)" + ch);
var result = re.Replace(str, "${1}y");
Console.WriteLine(result);
Tested result:
Hope this could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.