RegExp: incrementing digit in replacement expressions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, before coming to .NET, I utilized regular expressions mostly in JScript /
JavaScript and also in my favorite text editor: TextPad (www.textpad.com)

I don't know about JScript/JavaScript, but in TextPad's implementation of
Regular Expressions, you can do a replacement expression like this: \i

For every single non-overlapping match, it places an incrementing number
starting with zero. Thus, if you searched for ^ (beginning of line anchor)
and replaced it with \i you could quickly add line numbers into your document.

You can also do a replacement expression like this: \i{5,10} which also
replaces every single non-overlapping match with an incrementing digit that
starts at 5 and increments by 10, etc.

I've read through all of my MSDN documentation that came with Visual
Studio.NET, and I can't find a simple replacement expression like this at
all. It looks like I would have to revert to using the Match Collection
somehow.. but that doesn't really help me place digits back into the original
input string.

Any ideas?

Thanks,

B.KeithW
 
brian said:
replacement ... like this: \i
places an incrementing number
starting with zero.
I've read through all of my MSDN documentation that came with Visual
Studio.NET, and I can't find a simple replacement expression like this at
all. It looks like I would have to revert to using the Match Collection
somehow.. but that doesn't really help me place digits back into the original
input string.

Look at the Regex.Replace overloads that take a MatchEvaluator
delegate.
 
Back
Top