Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find and replace in files - .NET friendly regular expression syntax

Tags:

regex

replace

I'm looking for a decent tool that can do search and replace over multiple files, with regular expression syntax I'm use to in C#. Normally I would do this in Visual Studio, except it has the strangest regex syntax (and this is meant to be faster than just replacing the text in the files manually).

So far I've tried windows grep but it didn't like the regex below. The regex in question is

<see cref="(?<class>.+)">(.+)</see>

To replace with

<see cref="${class}"/>

Alternatively converting this to Visual Studio's syntax would be fine!

Jeff has a whole post on this on his blog.

like image 567
Chris S Avatar asked Dec 08 '25 13:12

Chris S


1 Answers

In Visual Studio, find:

\<see cref="{:i}"\>.*\</see\>

and replace with:

<see cref="\1"/>

{} is the VS grouping operator. It is not named. In replacements \n is used for the value of the n-th group in the find expression.

You can tweak the :i and .* parts if you need to account for new lines or other whitespace.

like image 93
Franci Penov Avatar answered Dec 11 '25 02:12

Franci Penov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!