views:

1925

answers:

2

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

+3  A: 

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.

I'd suggest using an editor with a proper regex implementation like gvim or UltraEdit. I've never understood how people use Notepad++, whenever I've tried to use it, everything in it has seemed incomplete.

Chad Birch
+1  A: 

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.

Gumbo