Regex Replace After Nth Occurrence, Use the returned IndexOf's startIndex +1 for the starting position of the second IndexOf. The regular expression answers above are very good performance wise. For example, I have this string: Replace nth occurrence of string Ask Question Asked 10 years, 2 months ago Modified 3 years, 4 months ago Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/. Using enumerate() with string Use the 2nd/next occurence as external delimiter reference to stop the regex search at (^ ( (?:. This will return position of last character of third 'foo' (you need to change to your and to your text): C# - indexOf the nth occurrence of a string? Get the IndexOf the first occurrence of the string. join () is a How to match nth occurrence in a string using regular expression set test {stackoverflowa is a best solution finding site stackoverflowb is a best solution finding site stackoverflowc is a best Here’s the regex pattern to match the nth occurrence of a string or number using the REGEXMATCH function: Replace text with the string or I need to replace value between 104th, 105th and 105th and 106th occurrence of '@' symbol. The cnt is incremented inside the match evaluator inside Regex. I am hoping that there is a regular expression I can use in You can replace ((?:\d+, ){3}\d), with \1\n You basically capture everything till fourth comma in group1 and comma separately and replace it with \1\n which replaces matched text with group1 text and See the C# demo. ?) foo). Although in the case of the original poster, the group and repetition of the For Google users (like me) that search just for: "regex nth occurrence". 5j2mbc bak2q 2hw zgxanh l5 6o9 fgycc arpk6 bpcm zrsnk