Regex for VS Code and IDE Search

Regex patterns and search/replace recipes for VS Code, JetBrains IDEs, and common editor refactors.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## VS Code Find and Replace
Enable regex mode in search
.*

# Use regex search in VS Code find/replace.

Add commas to object properties
^(\s*[A-Za-z_$][\w$]*\s*:\s*.+?)(?<![,{\[])\s*$

# Find non-final object property lines missing a comma.

Convert quoted words
"([^"
]*)"

# Find double-quoted word-like strings.

Find console logging
\bconsole\.log\s*\([^)]*\)\s*;?

# Find common `console.log(...)` calls.

Find TODO-like tags
\b(?:TODO|FIXME|HACK|NOTE)\b.*

# Find TODO, FIXME, or HACK comments.

Match across multiple lines
useEffect\s*\(\s*\(\)\s*=>[\s\S]*?\)\s*,\s*\[[^\]]*\]\s*\)

# Find a React `useEffect` block or similar code span.

## JetBrains IDE Recipes
Capture ES import path
import\s+.*?\s+from\s+['"]([^'"]+)['"]

# Find JavaScript/TypeScript imports and capture the module path.

Find className/class attributes
\b(?:class|className)=["']([^"']+)["']

# Capture HTML or JSX class-like attributes.

Find numbered file suffixes
([._-])(\d+)(?=\.[A-Za-z0-9]+$|\b)

# Capture numeric suffixes in filenames or keys.

## Editor Refactor Recipes
Find simple `var` declarations
^\s*var\s+([A-Za-z_$][\w$]*)

# Find `var` declarations for modernization review.

Find CommonJS require calls
\bconst\s+([A-Za-z_$][\w$]*)\s*=\s*require\((['"][^'"]+['"])\)

# Find CommonJS imports for migration to ESM.

Find 3+ blank lines
(?:\r?
\s*){3,}

# Reduce excessive blank vertical spacing.

Find repeated spaces
 {2,}

# Match runs of multiple spaces.

Recommended next

No recommendations yet.