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
\s+$

# Match spaces at end of lines.

Collapse repeated blank lines
Find: 
{3,}
Replace: 

# Reduce multiple blank lines to one.

Find TODO / FIXME markers
\b(?:TODO|FIXME|HACK|NOTE)\b

# Locate common work markers in code.

Find console.log statements
console\.log\s*\(

# Locate debugging logs in JS/TS.

Match quoted strings
(["']).*?\1

# Simple pattern to match single or double quoted strings.

## Replace Cookbook
Replace repeated spaces with one
Find: {2,}
Replace:  

# Normalize spacing.

Wrap matches in quotes
Find: (\w+)
Replace: "$1"

# Surround found words using capture groups.

Convert key: value style to quoted keys
Find: ^\s*(\w+)\s*:
Replace: "$1":

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

Prefix lines during replace
Find: ^(.*)$
Replace: // $1

# Insert comment prefix at the beginning of lines.

Recommended next

No recommendations yet.