Sign in to follow this  

Advanced Find + Replace

This topic is 3628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Often I need to go from something like: var = foo( a, b ); to foo( var, a, b ); Or something like this, where the calling convention has changed. Any idea of an easy way to do this w/o external scripting? (VS2005's reg expressions in their find/replace?) [VS2005/C++]

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
This article should help; http://visualapl.com/library/aplnext/mergedProjects/Visual%20Studio%20Book/Visual_Studio.htm


Ok those are some cool tips, but I need to do this en masse to the whole document, which it doesn't explain how to do. (The transpose is cool, and close, but no cigar.)

I can easily use regex's to remove things, i.e. go from

var = foo( a, b );

to

foo( a, b );

using a wildcard to spot variables like "var". But I don't know how to preserve that var name and move it somewhere (like into a first parameter).

Thanks if anyone else has ideas..

Share this post


Link to post
Share on other sites
Quote:
Original post by discman1028
But I don't know how to preserve that var name and move it somewhere (like into a first parameter).


Look at the "{} Tag expression" feature of regular expressions.

Share this post


Link to post
Share on other sites
I entered
Find what: {:w} = {(:w)}\({.*}\);
Replace with: \2( \1,\3)
(the { } capture strings, \n refers to the n-th captured string). Using this converted

var = foo( a, b );
bar = x( 1, 2, 3 );
z = test( func(55, 6), 5 + 9 );
into

foo( var, a, b )
x( bar, 1, 2, 3 )
test( z, func(55, 6), 5 + 9 )

which I believe you're after. You might have to add some extra stuff in your regex depending on your exact needs.

Share this post


Link to post
Share on other sites
Quote:
Original post by SamLowry
I entered
Find what: {:w} = {(:w)}\({.*}\);
Replace with: \2( \1,\3)
(the { } capture strings, \n refers to the n-th captured string).


Where do I find more options like :w? (What's :w mean?) It worked well, but sometimes it doesn't grab an alphanumeric string, only the alpha part.

Share this post


Link to post
Share on other sites
I've also recently seen this alternate syntax:

FIND WHAT:
new{[ \t]+[_a-zA-Z]}

REPLACE WITH:
my_new\1

It replaces the 'new' keyword used in code with 'my_new'.

So, what is :w for?? Seems like anything caught inside curly braces gets enumerated... why :w?

Share this post


Link to post
Share on other sites
Click the arrow button to the right of the 'Find what' text box and you'll get a pop up menu with various special character combinations you can use. The bottom most selection on the menu is 'Complete Character List'. Click that and it'll bring up the MSDN help page that explains what all the special character combinations are.

The character combination :w matches the expression ([a-zA-Z]+) - an alphabetic string. Particularly useful is :i which matches a C++ identifier.

Share this post


Link to post
Share on other sites
Quote:
Original post by mattnewport
Click the arrow button to the right of the 'Find what' text box and you'll get a pop up menu with various special character combinations you can use. The bottom most selection on the menu is 'Complete Character List'. Click that and it'll bring up the MSDN help page that explains what all the special character combinations are.

The character combination :w matches the expression ([a-zA-Z]+) - an alphabetic string. Particularly useful is :i which matches a C++ identifier.


That page is what I needed! Thanks.

Share this post


Link to post
Share on other sites

This topic is 3628 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this