7

I have a large text file and want to replace the 4th character of each line. Cloud you please suggest a Regex to do that in Notepad++?

2
  • what do you want to replace it with?
    – Rico
    Commented Jan 28, 2016 at 12:04
  • Welcome to SuperUser. Please notice that your requirement is not yet well-defined. With what is the character to be replaced? Also, here at SuperUser, you're supposed to show what you have already tried and explain the problems you had with that.
    – Run CMD
    Commented Jan 28, 2016 at 12:06

3 Answers 3

10

An alternate to replacing with find-replace is simply to mark every 4th character by setting your cursor on the 4th character in the first line, hold down SHIFT & ALT and then pressing the down button.

This will select 4th the character on every as a column.

6

search for ^(.{3}).(.*)
replace with \1a\2

Be sure to turn off the . match multiline.
This is untested; check if it does what you need. If you say more about the structure of your document; I may come up with a better regexp.

1

If you want to replace the character at the 4th position with X, press Ctrl+H and select Regular expression as the Search Mode and use any of the these:

  • Find what: ^(...)(.)
    Replace with: \1X

  • Find what: ^(.{3})(.)(.*)$
    Replace with: \1X\3

  • Find what: ^(.{3})(.)
    Replace with: \1X

An alternative solution for smaller files

Hold down Alt and with your mouse, drag over and select the column of text you want replaced.

Notepad++ column edit

You can also do this with just the keyboard by holding down Alt+Shift and then selecting the column of text you want to replace using arrow keys and then typing over it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .