Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex OR in notepad++

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.

What is Notepad RegEx?

Regex Special Characters . or \C ⇒ Matches any character. If you check the box which says . matches newline, the dot match any character, including newline sequences. With the option unchecked, then . will only match characters within a line, and not the newline sequences ( \r or \n ).

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.

How do I Find patterns in Notepad++?

Ctrl+F will bring up the search window. Click on the Find in Files tab. Note: This tab has a specific shortcut – Ctrl+Shift+F – and can be found in the Search menu.


Looks like Don Ho added the RegEx OR | operator to the Notepad++ native Find in the
latest version of Notepad (ver. 6.1.1).
Download Notepad 6.1.1 from here

Install Notepad 6.1.1, then go to Search->Find
Find what: action(421|732|983)
Search Mode: (*) Regular Expression

Click on the Find Next button


It is now possible in Notepad >= 10.1.1. According to Dragos Toader: "The latest version as of today (Notepad 10.1.1) supports | in RegEx"

== original answer below ==

It's not possible in Notepad++. See this answer.

But your regex is not correct. This one would work: action(421|732|983) if Notepad++ supported the | in regex.


You can use the regex helper plugin for Notepad++, but that is more for regex development than replace, but if you just want to find, I think this plugin can be helpful.

enter image description here


Notepad++ doesn't support the alternation operator|. You can try the textfx ctrl+R regexp option but I think the same is true.


Use the PythonScript Notepad++ plugin for Python Regular Expression search function.
See here for functions

Editor.pysearch(expression, function[, flags[, startLine[, endLine]]])

or

Editor.pymlsearch(expression, function[, flags[, startPosition[, endPosition]]])  

Here's a simple program using the python Regular Expression search function editor.pysearch()
I've left lots of debug code in so you can see what is happening during the course of the function run.

# $Revision: 1.3 $
# $Author: dot $
# $Date: 2012/04/19 00:03:26 $

from Npp import *
import re, string

expression = notepad.prompt(
                 "Enter the RegEx search string then press Enter",
                 "RegEx and Search" ,
                 "")

debug = True
#debug = False

if debug:
    bufferID = notepad.getCurrentBufferID()

if debug:
    # Show console for debugging
    console.clear()
    console.show()

if expression != None:
    expressionSansNl = expression.replace('\r\n', '')

    if debug:
        console.write( expression + "\n" )

    # First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script
    editor.beginUndoAction()

    if debug:
        console.write( 'editor.pysearch( r"%s" % expressionSansNl, None)\n' )

    editor.pysearch( r"%s" % expressionSansNl, None)

    # End the undo action, so Ctrl-Z will undo the above two actions
    editor.endUndoAction()

# Debug
if debug:
    notepad.activateBufferID(bufferID)

Map this script to Notepad++ shortcut Ctrl+<ChooseALetter> and run it.
Type in search RegEx action(421|732|983)
According to Python re documentation here, the | RegEx operator is supported.

I haven't tested this -- maybe the None parameter in the pysearch() function needs
to be a function that will select the resulting string. According to to docs here,
the function should return a python MatchObject. I think there's a way to get the
matching string from the MatchObject and select the next appearance of that matching
string in the editor object. I'll post a new revision of the answer once I'm done coding
and testing this.