Notepad++ regex -> newLine

前端 未结 5 1753
孤街浪徒
孤街浪徒 2021-01-06 03:02

I use Notepad++ and I need to delete all lines starting with, say \"abc\".

Attention, I don\'t need to replace the line starting with \"abc\" with a empty line, but

相关标签:
5条回答
  • 2021-01-06 03:28

    Try the regex \nabc.* in "Find and Replace" --> "Replace"
    Leave "Replace With" field empty.

    EDIT : This won't work with first like (because '\n' means "new line")

    0 讨论(0)
  • 2021-01-06 03:29

    Press Ctrl+H to bring up the Replace window. Put

    ^abc.*(\r?\n)?
    

    in the Find what and leave Replace with empty. Select Reqular expression and hit Replace All.

    This reqular expression handles all the edge cases:

    • When the first line of the file starts with abc
    • When the last line of the file starts with abc and there is no new line at the end of the file.
    0 讨论(0)
  • 2021-01-06 03:30

    Searching a little bit more on regex in Notepad++ I discovered that the new line character is not \n as I expected (Windows), but the \n\r.

    So, my regex replace expression should be:
    Find: abc.*\r\n
    Replace with: (nothing, empty field)

    0 讨论(0)
  • 2021-01-06 03:36

    Search for this regular expression

    ^abc.*\r\n
    

    Replace with nothing.

    0 讨论(0)
  • 2021-01-06 03:37

    Try replace

    ^abc.*(\r?\n)?
    

    with

    nothing
    

    The ^ indicates the start of a line.

    The . means wild-card.

    The .* means zero or more wild-cards.

    x? means x is optional.

    The \r?\n covers both \r\n (generally Windows) and \n (generally Unix), but must be optional to cover the last line.

    0 讨论(0)
提交回复
热议问题