Community
    • Login

    Copy and Replace

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 2.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • COURTNEY sC
      COURTNEY s
      last edited by

      Hi! I have multiple files that I would like to change using a find and replace function. Each file has different text on line 5, and ‘EN’ as the last line. I would like to find a way to copy Line 5 and paste within a new text statement everytime it states ‘EN’ on multiple files without entering each one.

      Example:
      Line 1
      Line 2
      Line 3
      Line 4
      1234
      EN

      Replace with :
      Line 1
      Line 2
      Line 3
      Line 4
      1234
      New text 1234
      EN

      Is there a way to do this without going into each file?

      1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones
        last edited by PeterJones

        Your spec is rather ambiguous, but I think this will do what you asked for (in that it mimics the output):

        • Find what : (?-s)^(.*$\R)^(EN)$
        • Replace with : $1New text $1$2
        • ☑ Regular Expression
        • Make sure you’re on the Find in Files tab

        Find details:

        • (?-s) = make sure . does not match EOL characters (this will ensure that the next parenthetical will only match one line’s worth
        • () = Everything inside parentheses gets put into the next $# variable
        • ^ = matches the beginning of a line
        • $ = matches the end of a line
        • \R = matches the EOL character sequence (whether it’s a linux LF or windows CR+LF or old mac CR)
        • ^(.*$\R) = combining concepts above: match all the text between the start and end of line, plus the EOL sequence, and store it all in $1
        • ^(EN)$ = match the entire line matching EN, and store EN in $2

        Replace details:

        • $1: quote the values in $1, so it will be the fifth line and its new-line sequence
        • new text $1: add “New text”, followed by a space and the full contents of the fifth line (including its newline)
        • $2: quote the EN

        P.S. :
        (paraphrasing @guy038, the forum’s regex guru, who compiled these great regex resources, but hasn’t shared them in this thread yet):

        Here is a good starting point for NPP users unfamiliar with regular expression concepts and syntax:

        • http://docs.notepad-plus-plus.org/index.php/Regular_Expressions

        Modern Notepad++ (since v6.0) uses the Boost C++ Regex library, v1.55.0 (similar to the Perl Regular Common Expressions (PRCE), v5.8):

        • search syntax: http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
        • replace syntax: http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

        Other sites with valuable regular expression information include:

        • http://perldoc.perl.org/perlre.html
        • http://www.regular-expressions.info
        • http://www.rexegg.com
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors