fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var s = "=StringOne&=StringTwo&=StringThree&=StringFour&";
  12. var idx = 2; // Replace this occurrence
  13. var result = Regex.Replace(s, $@"^(=(?:[^=&]+&=){{{idx-1}}})[^=&]+", "${1}REPLACED");
  14. Console.WriteLine(result);
  15. }
  16. }
Success #stdin #stdout 0.03s 134720KB
stdin
Standard input is empty
stdout
=StringOne&=REPLACED&=StringThree&=StringFour&