Visual Studio 200X (IDE) - Regular Expressions
-
Wednesday, January 31, 2007 10:59 PMModerator
The regular expressions in Visual Studio 2003/2005/2008 are not the same as .Net Regular Expressions found in code. For that resources check out Regular Expression Resource.
If you are reading this you no doubt have questions about Visual Studio's version of Regular Expressions which is totally different from .Net Regular Expressions or any other flavor.
The differences between .Net and Studio's version are best summed up here by Jeff Atwood's Coding Horror: Visual Studio IDE and Regular Expression.
Of course to do any search or replacing, one will need to use the syntax. That is provided here Regular Expressions Visual Studio.
Here are two examples and notes to do a search and replace that I have in my notes which I will share with you.
I ran into a situation where I had to refactor text within a few documents. I had never used the Regular expressions in studio during search and replace and decided to learn something new. I had in the text files text that had a pattern like this:
return data["COVERAGE_ELECT"]
and needed to change each similar occurance to this:
return ProcessDataString("COVERAGE_ELECT");
Here is the search text I created which specified that the quoted string would be saved into a Visual Studio set (as seen in the {} ) which would create a match that would later be accessed in the replacement text by the Visual Studio replace \1:
At that point I could search the file and replace at will.
Next Replace:
Change p-nikko-copy-cp2 to p-nikko-copy2-cp but also allow for other numbers. This was basically moving the digit at the end to the previous section.
Here is the replacement.
That found over 18 occurances and moved a number into the previous sections location.
Notes
- Some regular expression syntax used by studio is not the same as the standard Regular Expression, such as usage of :a instead of \w or :z for \d.
- \1 through \9 matches can be parsed or use of \0 for all matches.
- Must check Use: Regular Expressions in the dialog.
Links
- Regular Expression to turn public fields into public properties by Merrick Chaffers
- Edited by OmegaManMVP, Moderator Sunday, September 07, 2008 2:27 AM Added 2008
- Some regular expression syntax used by studio is not the same as the standard Regular Expression, such as usage of :a instead of \w or :z for \d.
All Replies
-
Thursday, June 05, 2008 2:00 PM
I'd like to suggest my recently released tool Regent. It automatically creates search and replace regular expression from text example and has explicit support for Visual Studio's version of regular expressions.
-
Wednesday, December 17, 2008 6:41 AMIt is most useful control to validate the regular expression fields.
Pandi -
Monday, August 02, 2010 3:55 PM
Hi guys.
I am really love the MS VS IDE for its regular expressions and im a frequent user of that capability. Im using VS IDE always when i need to process text files i need - VS IDE is my No1 instrument in such tasks.
But despite all beauty of this capability in IDE there are many bugs in its' functioning. I changed 3 version of MSVS (2005, 2008, 2010) and many of these bugs still there.
Does MS programmers correcting bugs in IDE regular expressions at all?
I cant write particular bugs descriptions here at moment of writing this message (cuz im oriented to perform my tasks first than search the bugs in VS), but if you try to process files with VS IDE regular expressions for long period - you should meet all these surprises well. And of course, now i will post about each bug i encountered and remembered here in this thread.
-
Monday, August 02, 2010 7:16 PMModeratorAnything that is a bug should be fixed. Post the exact issue to Microsoft Connect Visual Studio and .Net Framework . Keep us informed of your progress.
William Wegerson (www.OmegaCoder.Com) -
Sunday, September 05, 2010 3:58 AM
Hi guys.
I am really love the MS VS IDE fo its regular expressions and im a frequent user of that capability. Im using VS IDE always when i need to process text files i need - VS IDE is my No1 instrument in such tasks.
But despite all beauty of this capability in IDE there are many bugs in its' functioning. I changed 3 version of MSVS (2005, 2008, 2010) and many of these bugs still there.
Does MS programmers correcting bugs in IDE regular expressions at all?
I cant write particular bugs descriptions here at moment of writing this message (cuz im oriented to perform my tasks first than search the bugs in VS), but if you try to process files with VS IDE regular expressions for long period - you should meet all these surprises well. And of course, now i will post about each bug i encountered and remembered here in this thread.
This is what I'm looking for, Nice writing, Now I understand more about it, Thanks for your explanation!

