How do you use Notepad++ regex pipe | for strings longer than one character?

后端 未结 5 2283
不知归路
不知归路 2020-12-18 18:54

I\'m trying to get notepad++ to regex find all instances of \"abc\" and \"def\" in the following sentence:

The abc went to the def.

相关标签:
5条回答
  • 2020-12-18 19:40

    Upgrade to Notepad++ v6. From the changelog: "PCRE (Perl Compatible Regular Expressions) is supported." I've verified that | works in regex search when using Notepad++ v6.

    0 讨论(0)
  • 2020-12-18 19:45

    I was having the same problem, which is how I landed here. Since it's a notepad++ deficiency, we can make do by using Powershell. In your case, simply run a Select-String:

    `ss abc,def filename`
    

    If on Unix then you have other tools like grep of course.

    I recognize you wanted a solution for notepad++, and so do I, but sometimes you have to make do.

    0 讨论(0)
  • 2020-12-18 19:53

    The | should work now.
    Thanks to the Regex improvements in Notepad++

    abc|def
    
    (abc)|(def)
    
    0 讨论(0)
  • 2020-12-18 19:54

    Inside a character set declaration ([…]) only the characters \, ] and - are special characters with the special functions of escaping the next character, closing the character set declaration and marking a character range (only if not written at the begin or end), respectively. Any other character is interpretet as a plain character.

    So is your | in [a|d] which means that [a|d] describes any of the characters a, | or d and not just a or d like a|d does.

    0 讨论(0)
  • 2020-12-18 19:59

    It's nothing special about "longer than one character", Notepad++ doesn't support the | character in regex. Not even "a|d" works. See the regex help page. Version 6.1.1 of Notepad++ now supports |.

    I'd suggest using an editor with a proper regex implementation like gvim or UltraEdit.

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