Search code examples
notepad++

Adding characters to the first of lines with 60 or more characters


I want to adding character to the first of lines with 60 or more characters, how can I do this?

I used this (.{60})\s to search, but I don't know what to put in replace


Solution

  • You may want to use a capturing group starting at begin of a line. You'd go through following steps:

    • Ctrl+H
    • Find what: (^.{60})
    • Replace with: added text\1
    • Tick the Wrap around option
    • Search mode: Regular expression
    • Click on Replace All (at your own risk)

    is resulting in:

    enter image description here

    The replacement addedtext\1 is beginning with some text and adds the text stored by the capturing group.

    Some additional information about reinserting text matched by capturing groups in the replacement text:

    The \1 syntax for backreferences in the replacement text is borrowed from the syntax for backreferences in the regular expression. \1 through \9 are supported by the JGsoft applications, Delphi, Perl (though deprecated), Python, Ruby, PHP, R, Boost, and Tcl.

    $1 through $99 for single-digit and double-digit backreferences are supported by the JGsoft applications, Delphi, .NET, Java, JavaScript, VBScript, PCRE2, PHP, Boost, std::regex, and XPath.

    Quoted from: Numbered Backreferences

    Notepad++ regular expressions use the Boost regular expression library v1.80 (as of NPP v8.4.7), which is based on PCRE (Perl Compatible Regular Expression) syntax.