System.Text.RegularExpressions

  • Thread starter Thread starter Jeroen Vandezande
  • Start date Start date
J

Jeroen Vandezande

Hi,

I want to do the following:

"Pete jan jan john jan mark" --> "Pete B jan john jan mark"

So I would like to wite a RegEx that would replace the first occurence of
the matched string (in this case replacing "jan" by "B")
..replace replaces all occurences, but maybe a smart regex would solve that,
or let them find all occurences and use MatchEvaluator to only replace the
first and copy all the others back?
Any good Ideas?


Best Regards,

Jeroen Vandezande.
 
Jeroen,

The Replace method on the Regex object has an overloaded method that
allows you to specify how many times you want to perform the
replacement. That should allow you to limit the replacement to only
the first occurence.
 
Back
Top