Multi-line regular expressions in Visual Studio
Use (.*\n)*?
to skip zero or more lines between your expressions.
start(.*\n)*?end
finds
start
two
three
end
?
is the non-greedy operator, used to skip as few lines as possible.
If end
is not the first word in the line, add .*
to match the extra characters. I.e.: start(.*\n)*?.*end
finds
start
two
three
four end end
If you only want to replace until the first end
, add another non-greedy operator: start(.*\n)*?.*?end
.
Historic: In Visual Studio 2017 (and early versions of 2019) you can also use the single line option in the Find and Replace dialog Ctrl-Shift-F like this:
(?s)start.*end
For more see the version history of this answer.
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