469,927 Members | 1,853 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

RegExp: incrementing digit in replacement expressions

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
Nov 22 '05 #1
2 3396
brian wrote:
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.

--

still in the sling!
Nov 22 '05 #2
Jon,

thanks for the reply, this is definitely what I was looking for.
You're the man.

B

"Jon Shemitz" wrote:
Look at the Regex.Replace overloads that take a MatchEvaluator
delegate.


Nov 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Lukas Holcik | last post: by
5 posts views Thread by Dr John Stockton | last post: by
10 posts views Thread by Jeff Sandler | last post: by
8 posts views Thread by Dmitry Korolyov | last post: by
7 posts views Thread by arno | last post: by
6 posts views Thread by Christian Sonne | last post: by
7 posts views Thread by RN1 | last post: by
4 posts views Thread by r | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.