Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com Sep 23 '12 at 11:47

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

1  
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
2  
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. –  Lamb Sep 23 '12 at 12:58
    
I would advice you to use Notepad++ macros instead. –  Lamb 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
add comment

1 Answer

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
2  
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
add comment

Your Answer

 
discard

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.