Search code examples
regexnotepad++backreferencecapturing-group

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.


Solution

  • 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.