Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

None of the following syntaxes seem to work:

  • abc|def
  • [abc|def]
  • (abc)|(def)
  • (abc|def)

NOTE: "[a|d]" matches any instance of "a" or "d" when I tested

like image 367
TomFuertes Avatar asked May 04 '09 16:05

TomFuertes


People also ask

Can I use RegEx in Notepad?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

Can you pipe RegEx?

A pipe symbol allows regular expression components to be logically ORed. For example, the following regular expression matches lines that start with the word "Germany" or the word "Netherlands". Note that parentheses are used to group the two expressive components.

What type of RegEx does Notepad++ use?

FYI Notepad++ supports “PCRE” (i.e. PERL Compatible Regular Expressions) using Boost's RegEx library which is different from the PCRE and PCRE2 libraries.


2 Answers

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.

like image 97
Chad Birch Avatar answered Oct 04 '22 23:10

Chad Birch


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.

like image 28
MALfunction84 Avatar answered Oct 05 '22 01:10

MALfunction84