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

Regex search patterns for editors and IDEs.

Enable regex mode in search

Use regex search in VS Code find/replace.

textANYvscodeidesearch
text
.*

Toggle the `.*` regex icon in Find or Search. Then use patterns like the examples below.

Add commas to object properties

Find non-final object property lines missing a comma.

regexANYvscodejavascriptreplace
regex
^(\s*[A-Za-z_$][\w$]*\s*:\s*.+?)(?<![,{\[])\s*$

Useful when cleaning up JS/TS object literals. Verify carefully before replace-all.

Convert quoted words

Find double-quoted word-like strings.

regexANYvscodequotesreplace
regex
"([^"
]*)"

Can be replaced with '$1' wrapped in single quotes if the file style requires single quotes.

Find console logging

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

regexANYvscodejavascriptcleanup
regex
\bconsole\.log\s*\([^)]*\)\s*;?

Useful for cleanup before shipping code.

Find TODO-like tags

Find TODO, FIXME, or HACK comments.

regexANYvscodecommentsworkflow
regex
\b(?:TODO|FIXME|HACK|NOTE)\b.*

High-value search for code review and cleanup.

Match across multiple lines

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

regexANYvscodemultilinereact
regex
useEffect\s*\(\s*\(\)\s*=>[\s\S]*?\)\s*,\s*\[[^\]]*\]\s*\)

VS Code uses a JavaScript-like engine, so `[\s\S]` is a common any-character-across-lines technique.

JetBrains IDE Recipes

Common regex patterns for JetBrains Find in Path and Replace.

Capture ES import path

Find JavaScript/TypeScript imports and capture the module path.

regexANYjetbrainstypescriptimports
regex
import\s+.*?\s+from\s+['"]([^'"]+)['"]

Useful for auditing imports or bulk edits.

Find className/class attributes

Capture HTML or JSX class-like attributes.

regexANYjetbrainshtmljsx
regex
\b(?:class|className)=["']([^"']+)["']

Useful for CSS cleanup and component audits.

Find numbered file suffixes

Capture numeric suffixes in filenames or keys.

regexANYjetbrainsfilesparsing
regex
([._-])(\d+)(?=\.[A-Za-z0-9]+$|\b)

Useful when normalizing artifact names.

Editor Refactor Recipes

High-value search-and-replace recipes used during refactors.

Find simple `var` declarations

Find `var` declarations for modernization review.

regexANYrefactorjavascript
regex
^\s*var\s+([A-Za-z_$][\w$]*)

Helpful in older JavaScript codebases.

Find CommonJS require calls

Find CommonJS imports for migration to ESM.

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

Useful when converting Node projects to ESM.

Find 3+ blank lines

Reduce excessive blank vertical spacing.

regexANYrefactorformatting
regex
(?:\r?
\s*){3,}

Good cleanup recipe during formatting passes.

Find repeated spaces

Match runs of multiple spaces.

regexANYrefactorcleanupwhitespace
regex
 {2,}

Useful in prose, YAML, or hand-edited lists.

Recommended next

No recommendations yet.