Regex: replace first occurence only?

  • Thread starter Thread starter Alexey Smirnov
  • Start date Start date
A

Alexey Smirnov

Regex.Replace("BUILDING IN PARIS, IN LONDON" ,"\bIN\b","???");
returns "BUILDING ??? PARIS, ??? LONDON"

I need to replace the first match only, to have "BUILDING ??? PARIS, IN
LONDON"

How can I do that?

Thanks.
 
Hi Alexey,

Many of the overloads of the Regex.Replace method allow you to choose a
number to specify the number of occurrences of a match that you would
like to replace. Check them out and choose the one that is most
appropriate for you.

Possibly, you could use this one : Regex.Replace("input",
"replacement", count)...

Regards,

Cerebrus.
 
Back
Top