Multiline regular expression search doesn't work in VS Code version 1.27.2 .
Theoretically aaa(\n|.)*bbb
should find string starting from aaa and ending bbb but it doesn't work.
The solution mentioned here Multi-line regular expressions in Visual Studio Code doesn't work as well.
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.
Select the lines you want and then press: Windows: Shift + Alt + i. Mac: shift + option + i.
Multi-word: Ctrl+Shift+L / ⌘+Shift+L selects all instances of the current highlighted word.
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.
Multiline search is added in v1.29 released in November 2018. See multi-line search.
VS Code now supports multiline search! Same as in the editor, a regex search executes in multiline mode only if it contains a \n literal. The Search view shows a hint next to each multiline match, with the number of additional match lines.
This feature is possible thanks to the work done in the ripgrep tool to implement multiline search.
Multiline search is coming to the Find Widget with v1.38. See multiline find "pre-release" notes.
Multi Line search in Find Widget
The Find Widget now supports multiple line text search and replace. By pressing
Ctrl+Enter
, you can insert new lines into the input box.
.
Odd that it is Ctrl+Enter in the Find Widget but Shift+Enter in the Search Panel (see Deepu's answer below). Shift+Enter has other functionality when the Find Widget is focused.
yes, you could use regex for mutliple line search in VScode.
To find a multi-line text block starting from aaa
and ending with the first bbb
(lazy qualifier)
aaa(.|\n)+?bbb
To find a multi-line text block starting from aaa
and ending with the last bbb
. (greedy qualifier)
aaa(.|\n)+bbb
I have been looking for a quick way to do this, and I have come to the following:
start_text.*?(.|[\n])*?end_text
with start_text and end_text being the bounds of your multiline search.
breaking down the regex ".?(.|[\n])?":
<meta.*?(.|[\n])*?/>
will match from the beginning of all meta tags to the end of the respective tags<script.*?(.|[\n])*?</script>
will match from the beginning of all script tags to the respective closing tagsUsing .*?(.|[\n])*?
with improperly or partially filled in start_text or end_text might crash VS Code. I suggest either writing the whole expression out (which doesn't cause a problem) or writing the start and end text before pasting in the regex. In any case, when I tried to delete parts of the starting and ending text VS Code froze and forced me to reload the file. That being said, I honestly could not find something that worked better in VS Code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With