Removing lines selected with regex in VSCode

Dec 26, 2022 · 1 min read · Post a comment

Removing certain repeatable lines on a blog site with almost 600 posts (at the time of drafting) is impossible task (if you do it manually of course), so you got to rely on regular expressions (regex) as an only feasible option. Here’s a neat trick you could try to delete selected lines with regex.


  • VSCode


Step 1. Click on the Search (🔎) icon, on the top left (Command + Shift + F on macOS).

Step 2. Enable regex by clicking on .*. VSCode enable regex

Step 3. Let’s try matching every line that starts with tags.

tags: \[.+\n

VSCode tags regex example

\[.+\n breakdown:

  • \[: escape special character [.
  • .: match any character.
  • +: one or more times.
  • \n: new line.

Step 4. Click on the Replace box, and hit Shift + Enter (macOS).

VSCode tags regex replace

If that doesn’t work, try with one of the following: Alt + Enter, Ctlr + Shift + K, or Command + Shift + K (macOS).

Step 5. Finally, click Replace All button found just on the right side (Option + Command + Enter on macOS).

VSCode tags regex replace all

remove empty lines in VSCode

Step 1. In the search box, enable regex (take a look at Step 2 above).

Step 2. In the Find box, type: \n\n.

Step 3. In the Replace box, type: \n.

Step 4. Click Replace All.


Related post: Wildcard regex in VSCode.

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.