143

I have this regular expression to find certain keywords on a line:

.*(word1|word2|word3).*

In the find and replace feature of the latest VSCode it works ok and finds the words but it just blanks the lines leaving big gaps in-between.

I would like to delete the entire line including linefeed.

The find and replace feature doesnt seem to support reg exp in the replace field.

2

3 Answers 3

361

If you want to delete the entire line make your regex find the entire line and include the linefeed as well. Something like:

^.*(word1|word2|word3).*\n?

Then ALT-Enter will select all lines that match and Delete will eliminate them including the lines they occupied.

Sign up to request clarification or add additional context in comments.

6 Comments

Ctrl + Shift + K for delete line.
don't forget to enable regex
Command + Shift + K to delete line on Mac
You can also fire the replace with an empty field, instead of using a keyboard combination. It works fine also.
Dont work on linux. The line is cleaned but not deleted
|
20

Mark's answer as an example in VSCode

Mark's answer as an example in the VSCode screenshot for those who need extra guidance. Click on the '.*' icon followed by 'replace all' with a blank entry to delete, or your replacement text.

Clicking the X icon next to a result allows you to dismiss that result from the replace function

Dismiss result

Comments

2

I had need to remove lines with [,,] where some blank values from a DB export couldn't be tolerated in the database I was migrating to. The specific regex string to use there was

^.*,,.*?\n

Posting this for my own future reference as much as anything.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.