5,445,109 members and growing! (15,443 online)
Email Password   helpLost your password?
General Programming » Macros and Add-ins » VS.NET Add-ins     Intermediate License: The Code Project Open License (CPOL)

.NET Regular Expressions Find and Replace Add-In for Visual Studio 2005

By jhillman

A .NET Regular Expressions Find and Replace add-in for Visual Studio 2005
C# (C# 1.0, C# 2.0, C# 3.0, C#), XML, .NET, Visual Studio (Visual Studio, VS2005), Dev

Posted: 12 Jun 2008
Updated: 28 Jul 2008
Views: 10,094
Bookmarked: 48 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 5.92 Rating: 4.71 out of 5
0 votes, 0.0%
1
1 vote, 5.6%
2
1 vote, 5.6%
3
1 vote, 5.6%
4
15 votes, 83.3%
5
replace_in_files.PNG

Introduction

This add-in is for anyone who wants to use Regular Expressions to find and replace in Visual Studio, but doesn't want to use the strange Regular Expression syntax of the built-in dialog. This add-in provides a new dialog that uses .NET's Regular Expressions to find and replace.

Background

I worked on this a couple of years ago, so I don't remember everything that motivated me to do it. I was tired of the crippled version of Regular Expressions available within the Visual Studio IDE. I found this article about a Visual Studio add-in that sounded good enough, but it didn't work with Visual Studio 2005. My add-in is partly based on that add-in, with several bug fixes and additional features.

Using the Add-In

If you just want to use the add-in, download the add-in files and copy them to your "C:\Documents and Settings\<username>\My Documents\Visual Studio 2005\AddIns" directory. If you want to mess around with the source (or fix any glaring bugs), download the source and run the project.

To debug the project, move "RegexFindAndReplace - For Testing.AddIn" to "C:\Documents and Settings\<username>\My Documents\Visual Studio 2005\Addins".

You will also need to update the section that looks like this in RegexFindAndReplace.csproj:

<Content Include="C:\Documents and Settings\<username>\My 
         Documents\Visual Studio 2005\Addins\RegexFindAndReplace - For Testing.AddIn">
<Link>RegexFindAndReplace - For Testing.AddIn</Link>
</Content>

Within "RegexFindAndReplace - For Testing.AddIn", you need to update this section to point to the location of the project:

<Assembly><project directory>\RegexFindAndReplace\bin\RegexFindAndReplace.dll</Assembly>

The following Debug project settings also need to be updated:

  • Start external program: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe
  • Command line arguments: /resetaddin RegexFindAndReplace.Connect
  • Working directory: C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\

Once everything is installed, you will find a new entry in the Edit|Find and Replace menu:

menu.png

There is also a keyboard shortcut of Ctrl+Shift+X, for those of you who avoid the mouse when you can.

Points of Interest

This add-in provides most of the functionality as the built-in Find and Replace dialog, with a few additional options. In the Find in Files mode, the results are printed to the Output window:

output.PNG

To the right of the Find or Replace text boxes, there is a drop-down menu that has several common constructs used in Regular Expressions or replacement strings. The Captured sub-expressions menu lists all of the back references available, and when one is selected, the corresponding expression is highlighted in blue in the text box:

highlighted_subexpressions.PNG

I have had a lot of fun working on this; please contact me about feature requests or bugs, and I will do my best to make sure this is as useful as possible.

Limitations

Each file that is searched for matches is read into memory; this means that files too large to fit into memory will not be able to be searched with this dialog. The reason for this is that regular expressions can span more than one line. In the future, I may add a check for newline characters in the regular expression to see if the file can be processed one line at a time.

History

  • 13 Jun 2008
    • original article posted.
  • 28 July 2008
    • Improved algorithm for processing files in Find All and Replace All modes
    • Added "Stop" button to enable canceling a Find All or Replace All operation

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

jhillman


I am a software developer currently working in Bangkok, Thailand. I work primarily with C++ for my job, but I mess around with C#, Perl, and Windows PowerShell for fun.
Occupation: Software Developer
Location: Thailand Thailand

Other popular Macros and Add-ins articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 26 (Total in Forum: 26) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralFind in Entire Solution is broken and annoyingmemberRob Siklos6:45 18 Jul '08  
GeneralRe: Find in Entire Solution is broken and annoyingmemberjhillman1:53 19 Jul '08  
GeneralRe: Find in Entire Solution is broken and annoyingmemberjhillman19:54 22 Jul '08  
GeneralRe: Find in Entire Solution is broken and annoyingmemberjhillman3:52 26 Jul '08  
Generalgood jobmemberaruan14:59 11 Jul '08  
GeneralVS 2005 closes when searchingmembermikebk10:18 3 Jul '08  
GeneralRe: VS 2005 closes when searchingmemberjhillman17:50 3 Jul '08  
GeneralRe: VS 2005 closes when searchingmembermikebk7:50 7 Jul '08  
GeneralRe: VS 2005 closes when searchingmemberjhillman16:47 7 Jul '08  
GeneralRe: VS 2005 closes when searchingmemberjhillman23:40 10 Jul '08  
GeneralRe: VS 2005 closes when searchingmembermikebk8:39 14 Jul '08  
GeneralRe: VS 2005 closes when searchingmemberjhillman22:40 14 Jul '08  
GeneralRe: VS 2005 closes when searchingmembermikebk3:59 15 Jul '08  
GeneralRe: VS 2005 closes when searchingmemberjhillman5:16 15 Jul '08  
GeneralError when starting Visual Studio 2005memberLaoujin5:35 30 Jun '08  
GeneralRe: Error when starting Visual Studio 2005memberjhillman17:07 30 Jun '08  
AnswerRe: Error when starting Visual Studio 2005memberadparadox08:55 18 Jul '08  
GeneralWorks with 2008 as well?sitebuilderUwe Keim23:08 13 Jun '08  
GeneralRe: Works with 2008 as well?memberjhillman23:16 13 Jun '08  
GeneralRe: Works with 2008 as well?memberGreeeg0:50 14 Jun '08  
GeneralRe: Works with 2008 as well?memberjhillman4:44 14 Jun '08  
GeneralRe: Works with 2008 as well?memberGreeeg8:27 14 Jun '08  
GeneralRe: Works with 2008 as well?memberjhillman15:13 14 Jun '08  
GeneralRe: Works with 2008 as well?memberjhillman20:02 16 Jun '08  
GeneralGreat minds and all thatmemberSimon Capewell0:57 13 Jun '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Jul 2008
Editor: Sean Ewington
Copyright 2008 by jhillman
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project