How to Delete Entire Lines Containing String in VSCode's Search (Find in Files)
How can we delete entire lines containing some substring in VSCode’s Search: Find in Files
function?
Example scenario in VSCode
Suppose we have hundreds of files containing the line date: xxxx-xx-xx
, where xxxx-xx-xx
is a different date in every file.
We want to delete this entire line from every file, but we can’t directly search for each string.
Use regular expressions remove entire lines
Let’s fix this issue using regular expressions.
All the keyboard shortcuts are for Windows.
- Open VSCode’s
Search: Find in Files
(Ctrl
+Shift
+F
) - Use regular expressions (
.*
button orAlt
+R
) - Write the regular expression:
^.*[STRING].*$\n
, where[STRING]
is your substring- In our scenario:
^.*date.*$\n
- In our scenario:
- Replace with empty line
- Profit