Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would I use a regex in Visual Studio 2005's search / replace to increment a set of numbers by 1?

The search term is either {:z} or {[0-9]+}. I am unsure of the replace term. Using "\1" simply substitutes the tagged string, but doesn't allow for addition to it. For instance "\1 + 1" places "42 + 1" into the text if 42 was the tagged number.

Using "=" or "\=" as in the following question doesn't work (again, the = is simply placed in the resulting text).

This is the way to do this in VIM: vim regex increment all numbers by 1

share|improve this question

migrated from Sep 23 '12 at 11:47

This question came from our site for professional and enthusiast programmers.

Hmm... regex only finds text within text, it does not have any arithmatic operations built into it, so it can not for example take "9" and carry it into 2 digits to form "10". – Darryl Miles Sep 22 '12 at 21:18
This is possible in vim because you can evaluate arbitrary vim functions in the replacement. Unless VS has such a feature it's probably impossible. Why do this, by the way? Couldn't you factor any magic numbers into variables or defines? – sapht Sep 22 '12 at 22:52
You can create a simple program taking Text and Regex as input and generating the required text. But I think there is not inbuilt replace with increment functionality. – Ankit Mishra Sep 23 '12 at 12:58
I would advice you to use Notepad++ macros instead. – Ankit Mishra Sep 23 '12 at 13:00
Thanks for all of the answers, everybody. @sapht The numbers I was incrementing are already a set of #defines. I added a couple of items and renumbered some of them to keep them in logical order for what they represent. – Taylor Price Sep 23 '12 at 23:59

This isn't the exact answer to your question for which I hope you'll excuse me but I do hope it could be useful ;-)

There is a tool I created named ProjectBuildCounter. It is free, easy to use, no setup hassles and visual studio versions mess. Could use it for as many projects you want. You can download here. Usage info is available here.

share|improve this answer
Please do not use Super User to advertise your software - at least add the disclaimer that you are the author. – sblair Mar 31 '13 at 19:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.