C.W.K.
Stream
Lesson 09 of 10 · published

VS Code Find & Replace

~8 min · editor, vscode

Level 0Pattern-Curious
0 XP0/90 lessons0/15 achievements
0/100 XP to next level100 XP to go0% complete

Your everyday regex environment

VS Code's Find & Replace (Cmd/Ctrl+F for current file, Cmd/Ctrl+Shift+F for project-wide) supports regex when you toggle the .* button (or press Alt+R).

The flavor is JavaScript-style RegExp — most patterns from the JS lesson work directly.

Replacement syntax

Use $1, $2... for capture groups in the replacement field. $0 is the whole match. Named groups: $<name>.

Special replacements:

  • \n — newline (insert a line break)
  • \t — tab
  • \u$1 — uppercase the first character of group 1
  • \U$1 — uppercase entire group 1
  • \l$1 — lowercase the first character of group 1
  • \L$1 — lowercase entire group 1

The case modifiers are killer

Convert userName to USER_NAME: find ([a-z])([A-Z]), replace with $1_$2, then a second pass: find (\w+), replace with \U$1. Two passes, code modernized.

Other VS Code regex superpowers

  • Multi-line mode: Toggle the multi-line button (or press Ctrl+Enter in find box). Now \n matches newlines and you can match across lines.
  • Files to include/exclude: Restrict the search scope without writing complex shell commands.
  • Preserve case: Toggle to make replacements respect the original case (camelCase stays camelCase, etc.).

Code

VS Code regex examples·text
// Find: console\.log\((.*?)\);
// Replace: logger.debug($1);
//
// Converts every console.log to logger.debug across the file.

// Find: function (\w+)\(
// Replace: const $1 = (
//
// Converts function declarations to arrow assignments.

// Find: ([a-z])([A-Z])
// Replace: $1_\L$2
//
// Converts userName → user_name (camelCase to snake_case)

// Find: (\w+) (\w+)
// Replace: \U$1\E $2
//
// Uppercase the first word of each matched pair (\E ends the case modifier)

External links

Exercise

Open VS Code in any project. Use regex find/replace to: (1) find all camelCase identifiers in a file, (2) replace one specific function call signature using capture groups, (3) lowercase a series of constants. Don't save unless you mean to.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.