VScode Regex

Mastering search and replace regex in Visual Studio Code

Published: Wednesday, Dec 6, 2023 Last modified: Sunday, Jun 9, 2024

Imagine a file with comments that you needed to remove:

"Remove this silly comment please"

To match content between the quote and remove it, you could use this regex:


But what if the comment was multiline?

Remove this silly comment please
and this one too

You could use this regex:


You can do a lot more with regex in VS Code, like reusing what’s matched and changing case.

VS Code also has Multiline search input, which is useful for matching content across multiple lines.

Visual Studio Code uses the PCRE2 regex engine and you can test your regex here. However for workspace searches ripgrep/rust regex engine is used, and if the regex fails it will fall back to PCRE2.