Saturday, March 03, 2001 ..:: Home ::.. Register  Login
   TechTidBits (Blog)  

Using RegEx in VisualStudio's Find or Find and Replace window not working for you neither eh?

Apr 23

Written by:
Thursday, April 23, 2009 9:16 PM  RssIcon

Ever try to use the RegEx option in Visual Studio's Search and Replace dialog box?  RegEx is hard enough as it is without having to throw in Visual Studio's own little nuances, well read on for a bit of help.

Visual Studio's Find and Replace Dialog

Regular Expressions (aka regex) is cryptic, if you've ever tried to debug one of those regex statements, you know what I'm talking about!  If you haven't, you're in for a real treat (hint, start small, get the basics and work out in small chunks, also use it or lose it).  If you've ever tried to do a Find and Replace with Visual Studio, you probably noticed the listbox at the bottom of the Find options that has the Regular expressions option.

Did it work out well for you?  Were you able to get exactly what you wanted?  If not, then you're not alone!  I did that too (use the regex I thought I knew and started to love) then figured out that Visual Studio's Find and Replace dialog uses it's own flavour of regex!  DARN!  ANOTHER VERSION OF REGEX TO LEARN?!?!?!?!?!?!?  WTF?  AAAAHHH MAN!

But don't dispare!  Today I forced myself to try it out, and it's not all that bad!  MSDN has a quick page which talks about what you can do in that dialog, and for quick'n'dirty things, it's not that bad to read and then do!  Today I needed to replace a funky string for t-sql commands, and I needed to do it for every table in our db and it was getting VERY tedious doing it by hand!  Using the regex ("^.*SyncID.*int.*null.*$\n" replaced with nothing), I was able to do what I had to do in seconds!  AWESOME!  Luckily for me, the regex I needed was pretty standard stuff, but if you need to get trickier, I suggest taking a look at the MSDN page.

Now that you have a bit of time on your hands, go grab a coffee and get coding! :>




MSDN: Regular Expressions (Visual Studio)


Location: Blogs Parent Separator TechTidBits

2 comment(s) so far...

Re: Using RegEx in VisualStudio's Find or Find and Replace window not working for you neither eh?

I don't even bother dude. The fact that VS doesn't use .NET FRAMEWORK REGULAR EXPRESSIONS is incomprehensibly stupid to me. Don't pollute your mind and waste your time learning some one-off, hackneyed, WEAK regex flavor. Just use something else when you need regex. Personally I use Dreamweaver CS3/4, whose regex syntax is Perl-compliant (but which lacks some features too, like beginning of line anchor to name one), and whose global search and replaces are as fast as I have found on Windows.

-scott - Design and Programming For the Web.

By Scott Weaver on   Tuesday, May 19, 2009 9:07 AM

Re: Using RegEx in VisualStudio's Find or Find and Replace window not working for you neither eh?

I have to agree with you Scott on the "incomprehensibly stupid" comment! As much as it breaks my heart to say that about anything MS, it's try, I cannot for the life of me figure out why they did that? And their regex is so good in .NET, why can't they just reuse THOSE libraries, THEY'RE OWN LIBRARIES. gggrrrrr

re pollute your mind
That's also true, I found myself last week googling for how to do it AGAIN since I was trying to force myself to learn it, but after 15 fruitless minutes I just reverted back to the old wildcard strategy. Not perfect but it worked. I don't have Dreamweaver installed, but I'm sure I could get/use other regex tools, I've used Expresso in the past, very good product and the guys supports it himself, not some big corp.

Thank you for your comments Scott, I appreciate your feedback and I'm sure other's will too! Have a good day!

PS I poked around your website, you seem to be someone who knows a bit about web coding :) what do you think of IE8?

PPS You like intillectual "debates" I see from your About Me section. COOL! As much as I would disagree, my friends would say the same about me!LOL HAHA

By phenry on   Tuesday, May 19, 2009 9:20 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Add Comment   Cancel 
Copyright 1999-2012 by   Terms Of Use  Privacy Statement