Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
Removing Empty Lines
To remove empty lines from a file:
- Open Find and Replace (
Cmd+H) - Enable regex mode (click the
.*icon) - Search for
\n\nand replace with\n - Run “Replace All”
You may need to run it multiple times until you get down to single empty lines.
Pro tip: Use \n\n+ to replace all consecutive empty lines at once without repeating the operation.
Search and Replace with Regular Expressions
VS Code supports powerful regex-based find and replace. Here’s a real-world example:
Example: Wrapping Image Paths with Special Characters
Suppose you need to update image links with spaces in their filenames:

to:

Use this regex to find images with spaces:
!\[(.+)\]\((.*\s+.*)\)
This creates two capturing groups:
$1- the alt text$2- the filename
Then use this replacement:

For images without alt text, use:
!\[\]\((.*\s+.*)\)
With replacement:

Testing Regex
Use regex101.com to quickly test your regular expressions before using them in VS Code.