I'm unsure if this is possible, but I need to move all instances of the word USA to column 130 in a txt document using Notepad++.

I didn't "think" this would require any regex so I posted here, however I'm beginning to think otherwise.

I primarily need to know how to move just USA but knowing how to move it including everything after would be great so I don't have to come back and ask again. I tend to file these things away mentally or in a file to reference.


<titleid> <titlekey> <title> <random-number-of-spaces>     USA System Application

<titleid> <titlekey> <title> <random-number-of-spaces> USA System Application

Operating under the assumption the final result has the U from USA landing on column 130. I'd like to know how to move it by itself to that point, as well as it and everything beyond it if possible.

I have been able to scrape up some expressions to move forward by x number of tabs or preceding spaces, but nothing to move backwards. This is made complicated by the fact the end of the previous word, the <title> is of differing lengths and some instances of USA need to move forward, some backward, all need to end on the same column. Thus none fit what I am trying to accomplish.

For reference find \h+(?=USA\b) replace \t will handle moving forward by the number of tabs set in language preferences.

find (?:(USA.+)) replace $1 will move forward by the number of spaces preceding the $1 but does not aid in alignment due to the zig-zag pattern of the current state of the document.

  • Do you wish to just move USA, move USA and a following space, or USA plus everything remaining on the line up to the end of that line? Please click edit and tell us. – K7AAY May 22 at 21:29
  • 1
    It will be easier to answer if you give some sample lines of text and expected result. – Toto May 23 at 8:38

If you are sure there are only spaces at position 130 and just before, you can do in 2-step.

  1. Add 130 spaces before USA:
    • find what: \bUSA\b
    • Replace with: _________________$0 # (I use _ instead o space for better visual) add as many spaces as needed to move USA on each line ahead more than 130 characters from beginning of line.
    • CHECK Regular expression
    • Replace all
  2. Remove superfluous spaces before USA
    • Find what: ^.{129}\K\h+(?=\bUSA\b)
    • Replace with: LEAVE EMPTY
    • CHECK Regular expression
    • Replace all
| improve this answer | |
  • @klepp0906: If you add, let's say, 130 spaces, then, USA will be moved after position 130, then you'll got your result when you remove spaces between position 130 and the new position of USA. QED. – Toto May 23 at 15:18
  • that did it, thank you very much! – klepp0906 May 23 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.