Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use more than nine backreferences in Notepad++ regexp?

If I use a long regular expression in Notepad++, i.e.:

^([^ ]+) ([^ ]+) ([^ ]+) (\[.*?\]) (".*?") (".*?") (".*?") (".*?") (\d+) (\d+) (\d+)$

(this is for turning an Apache log lines from space-separated to tab-separated)

then I can't successfully use more than nine backreferences for replacing, as \10 yields the content of the first captured group plus a literal "0".

I tried with $10, but that gives the same result.

like image 739
watery Avatar asked Mar 15 '16 11:03

watery


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.

How do I change the pattern in Notepad?

A normal “Find and Replace” can't do that, but it's possible with “Regular Expressions”. In Notepad++ press Ctr+H to open the “Find and Replace” window. Under Search Mode: choose “Regular expression” and then check the “matches newline” checkbox. You should see closing </p> tags at the end of each line.

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 replace in Notepad++?

To replace text in Notepad++, follow the steps below. Open the text file in Notepad++. In the top menu bar, click Search and select Replace. In the Replace window, on the Replace tab, enter the text you want to find and the text you want to use as a replacement.


1 Answers

You can use curly braces for this:

${10}

For reference, Notepad++ uses boost::regex, and you can find its substitution pattern docs here: Boost-Extended Format String Syntax. This replacement mode allows for more complex expressions (like conditionals and common Perl placeholders) in the replacement pattern.

like image 169
Lucas Trzesniewski Avatar answered Oct 05 '22 23:10

Lucas Trzesniewski