VS Code Search and Regex

Search, replace, regex, and multi-file refactoring patterns in VS Code.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Regex Examples

Find trailing whitespace

Match spaces at end of lines.

regexANYregexcleanup
regex
\s+$

Collapse repeated blank lines

Reduce multiple blank lines to one.

regexANYregexcleanupreplace
regex
Find: 
{3,}
Replace: 

Find TODO / FIXME markers

Locate common work markers in code.

regexANYregexcomments
regex
\b(?:TODO|FIXME|HACK|NOTE)\b

Find console.log statements

Locate debugging logs in JS/TS.

regexANYregexjavascriptdebugging
regex
console\.log\s*\(

Match quoted strings

Simple pattern to match single or double quoted strings.

regexANYregexstrings
regex
(["']).*?\1

Replace Cookbook

Replace repeated spaces with one

Normalize spacing.

regexANYreplacecleanup
regex
Find: {2,}
Replace:  

Wrap matches in quotes

Surround found words using capture groups.

regexANYreplacecapture-groups
regex
Find: (\w+)
Replace: "$1"

Convert key: value style to quoted keys

Useful when massaging JS-like objects into JSON-like keys.

regexANYregexjsonreplace
regex
Find: ^\s*(\w+)\s*:
Replace: "$1":

Prefix lines during replace

Insert comment prefix at the beginning of lines.

regexANYreplacecomments
regex
Find: ^(.*)$
Replace: // $1

Recommended next

No recommendations yet.