Regex Find and Replace in VSCode: Complete Guide
Enable Regex Mode
Open find-and-replace (Cmd/Ctrl+Shift+H) and click the .* button. That's it. Now anything you type is treated as a regular expression.
Match Anything Between Quotes
"([^"]*)" finds all double-quoted strings. Use capture groups to swap them: replace with '$1' to convert double quotes to single quotes across an entire file.
Remove All Console.Logs
console\.log\(.*\); matches every console statement. Replace with nothing. I do this before almost every commit.
Rename Variables Across a File
If you need to rename oldVarName to newVarName but also catch old_var_name and oldVar, use word boundaries: \boldVar\w*\b. Preview the matches before replacing — regex is greedy and will surprise you.
Multi-Line Find
By default, . doesn't match newlines. Add [\s\S] instead of . when you need to match across lines. Like finding a function and its body: function oldFunc[\s\S]*?^}
A Safety Tip
Always preview the find results before hitting replace. Regex in VSCode doesn't have an undo for the whole replace operation — you're doing it file-wide. Check the count, then replace.