Quantcast
Channel: Jonathan's Blog
Viewing all articles
Browse latest Browse all 12

Espresso Tip: Find and replace Regex in Visual Studio

$
0
0

Every now and again you come across something really useful that you just have to share.

A few minutes ago that happened to me…

I had a bunch of code that looked like…

    var js = @Bundle.Javascript()
        .Add("script1.js")
        .Add("script2.js")
        .Add("script3.js")
        .Add("script4.js");
        // .... many more ....

And I needed to remove the .Add in place of actual script tags.

Of course I could have just manually done it, but I figured… I am smarter then all that!

So I hit Ctrl + h in Visual Studio to pull of Quick Replace and punched in a regex to find all of my .Adds.

Next, in VS Quick Replace you can use curly braces in your regex to capture stuff. So, my regex became…

\.Add\({.*}\)

Then you can use a \1 in the replace with to place the captured expression in the replace string.

That’s it! Thought that was worth sharing…

 

 

 

 

 


Viewing all articles
Browse latest Browse all 12

Trending Articles