Visual Studio Code - Removing Lines Containing criteria

RegexVisual Studio-Code

Regex Problem Overview


This probably isn't a VS Code-specific question but it's my tool of choice.

I have a log file with a lot of lines containing the following:

Company.Environment.Security.RightsBased.Policies.RightsUserAuthorizationPolicy

Those are debug-level log records that clutter the file I'm trying to process. I'm looking to remove the lines with that content.

I've looked into Regex but, unlike removing a blank line where you have the whole content in the search criteria (making find/replace easy), here I need to match from line break to line break on some criteria between the two, I think...

What are your thoughts on how criteria like that would work?

Regex Solutions


Solution 1 - Regex

If the criteria is a particular string and you don't want to have to remember regexes, there is a few handy keyboard shortcuts that can help you out. I'm going to assume you're on a Mac.

  1. Cmd-F to open find.
  2. Paste your string.
  3. Alt-Enter to select all of the instances of the string on the page.
  4. Cmd-L to broaden the selection to the entire line of each instance on the page.
  5. Delete/Backspace to remove those lines.

Solution 2 - Regex

I think you should be able to just search for ^.*CONTENT.*$\n, where the content is the text you showed us. That is, search on the following pattern:

^.*Company\.Environment\.Security\.RightsBased\.Policies\.RightsUserAuthorizationPolicy.*$\n

And then just replace with empty string.

Solution 3 - Regex

I have already up-voted answer of @james. But.. still I found one more easy and many feature available extension in VS Code. Here it is

It have much easy options to apply filters.

To match specific case mentioned in question. I am attaching screenshot which display how to use for it. I am posting this for others who come here in search for same issue. (Like I came) enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKillnineView Question on Stackoverflow
Solution 1 - RegexJamesView Answer on Stackoverflow
Solution 2 - RegexTim BiegeleisenView Answer on Stackoverflow
Solution 3 - RegexSanket PatelView Answer on Stackoverflow