Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-line regular expressions in Visual Studio

Is there any way to get Visual Studio to perform a regex replace across multiple lines (let the match cross line boundaries)? I know there are many editors I can use for this, but it seems strange that this feature has been left out of Visual Studio. Am I missing something?

like image 548
Paul Keister Avatar asked Oct 25 '10 17:10

Paul Keister


People also ask

What is multiline in regular expression?

Multiline option, or the m inline option, enables the regular expression engine to handle an input string that consists of multiple lines. It changes the interpretation of the ^ and $ language elements so that they match the beginning and end of a line, instead of the beginning and end of the input string.

How do you replace multiple lines in Visual Studio?

CHANGE: The default keyboard shortcut for “Multiline Find/Replace” was Ctrl+Alt+F but it was not applied because this shortcut was already taken by “F# Interactive”. So, the new default shortcut is Ctrl+M, Ctrl+F.

What regex does Visual Studio use?

Visual Studio uses . NET regular expressions to find and replace text.

How do I use regular expressions in Visual Studio search?

Vscode has a nice feature when using the search tool, it can search using regular expressions. You can click cmd+f (on a Mac, or ctrl+f on windows) to open the search tool, and then click cmd+option+r to enable regex search. Using this, you can find duplicate consecutive words easily in any document.


1 Answers

Regular expressions have changed in Visual Studio 2013. https://msdn.microsoft.com/en-us/library/2k3te2cs(v=vs.120).aspx

To match an expression over two lines the code would now be:

StartOfExpression.*\r?\n.*EndOfExpression

like image 60
Giles Roberts Avatar answered Oct 14 '22 18:10

Giles Roberts