Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
C# - How to find and replace every nth character occurrence using regex? Conversion from Javascript to C#

Find and replace every 3rd character occurrence in a given string and replace it with H

I found this Javascript code that does the same thing and would like to convert it into a C# code. Can you please assist ?

Found here

str = str.replace(/((?:[^x]*x){2}[^x]*)x/g, '$1y');

let str = 'I amx nexver axt hoxme on Sxundxaxs';
let n = 3;
let ch = 'x';

let regex = new RegExp("((?:[^" +ch+ "]*" +ch+ "){" + (n-1) + "}[^" +ch+ "]*)" +ch, "g");

str = str.replace(regex, '$1y');

console.log(str);
//=> I amx nexver ayt hoxme on Sxundyaxs
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!