By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,992 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,992 IT Pros & Developers. It's quick & easy.

RegExp: incrementing digit in replacement expressions

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.