Geeks With Blogs

News

qrcode

Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.

 Subscribe


Lance's TextBox » About Me » My Resume »Twitter

Here is a quick notes about using regular expressions in the VS2010 Find Replace dialog. 

1.  To create a backreference, use curly braces (“{“ and “}” ) instead of regular parentheses.

2.  To use the captured backreference, use \1\2 etc, where \1 is the first captured value, \2 is the second captured value, etc.

Example:

I want to find*:

info.setFieldValue(param1, param2);

and replace it with:

SetFieldValue(info, param1, param2);

To do this, I can use the following find/replace values:

Find what:

{[a-zA-Z0-9]+}.setFieldValue\({[a-zA-Z0-9., ]+}\);

Replace with:

SetFieldValue(\1, \2);

Use Regular Expressions is checked, of course.

*If you’re wondering why I’d want to do this – because I don’t have control over the setFieldValue function – its in a third party library that doesn’t behave in a very friendly manner.

Posted on Thursday, March 10, 2011 5:07 PM Programming | Back to top


Comments on this post: Visual Studio 2010 Find and Replace With Regular Expressions

# re: Visual Studio 2010 Find and Replace With Regular Expressions
Requesting Gravatar...
Thanks man, you saved me some precious time !
Left by David on Jan 11, 2012 11:03 AM

Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net