Global search and newline replacement in Visual Studio code

Suppose I want to delete all lines matching a regular expression in my project. Is there any way to do this?

Using a global search and replace function with regular expressions enabled, I tried:

  • Replace with foo|baran empty string. This does not work because it leaves a line there with an empty line. I want the new line to be deleted.

  • Replace with (foo|bar)\nan empty string. It really doesn't match anything.

  • Replace with (foo|bar)$an empty string. Again, nothing matches.

Any ideas?

Change . It looks like some of my files have Windows line endings, so it (foo|bar)\r?\nmatches. However, when you replace it with an empty string, in fact it still leaves the end of the string.

Here's a test case:

a
foo
b

This should end as follows:

a
b

Not this way:

a

b
+4
source share
2 answers

foo\n^and (foo|bar)\n^both work.

I just checked my code against - and you leave the replacement string blank

0
source

Yes, you can delete entire lines using the file search function.

, VSCode. VSCode 1.37.1, \n , . , (foo|bar)\n, , .

:

Screenshots before replacement

" ":

Screenshots after replacement

:

  • , CRLF.

  • ^ . , , , " " " ".

  • $ , . , ^.

  • , .

0

Source: https://habr.com/ru/post/1668720/


All Articles