search for specific text in columns 42-48 and replace with text in columns 49-55

  • John Iannucci
    John Iannucci

    Hello, I'm a newbie with NPP. I am looking to search for specific text in columns 42-48, and if that text matches (0), I wanted to insert the text from columns 49-55. Been playing with this for more hours than I would like to admit. I feel there is something simple, like adding certain characters to columns and what to search/replace for, just can not seem to find them. Can anyone help me out? Thank you in advance.

    Last edit: John Iannucci 2014-04-21
  • Open search and replace, check "Regular expression". If "ABCDEFG" the text which must be found in columns 42-48, write this in "Find what":


    And this in "Replace with":



    Take the first 41 columns, whatever they are, call them $1.
    Take columns 42-48 if they are "ABCDEFG".
    Take columns 49-55, call them $2.
    Take columns >= 56 if they exist, call them $3.

    Create the new line as:

    First 41 columns ($1), followed by columns 49-55 ($2) to replace ABCDEFG, then columns 49-55 ($2) again, and then the rest ($3).

    There are other things you can do with regular expressions, eg if you wanted to only match those lines where columns 42-48 are made up of digits you could do:


    Last edit: Andreas Jonsson 2014-04-21
    • John Iannucci
      John Iannucci

      Thank you Andreas. This is doing "exactly" what I need it to do. I wish I knew more about this, I've been reading up but it's not sinking in. Thank you again, and thank you for the very quick, accurate answer I was looking for. I own you one.


    Hi John, Andreas and All,

    I think that we can, even, shorten a bit this search/replacement :

    • Open the Replace dialog ( CTRL + H )

    • Check the Regular expression button

    • Check the Wrap around option, if necessary

    • Type in the Find what and Replace with zones, the regexes below :

    SEARCH : ^.{41}(.{7})\K

    REPLACE : \1

    • Click on the Replace All button

    Et voilà !

    To sump up, on each line of your file :

    • First, we count the 41 first characters

    • Then, we store the 7 further characters as the group 1 ( because of the round brackets )

    • Finally, due to the \K form, it forgets all the strings matched before. So the resulting search is only an empty string, located at column 49

    • This empty string is simply replaced by the group 1 ( the 7 characters, before the position 49, to duplicate ) :-)


    When a form \K is present in your regular search expression, you may click on the Find Next button to perform a step by step search.

    But, you CAN'T perform a step by step replacement ! You MUST perform a global search/replacement, by clicking on the Replace All button !!!

    Andreas, thanks for the link !



    Last edit: THEVENOT Guy 2014-04-29