Notepad++ Regex to replace the 4th character of each line in a text file.

3

2

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++?

user550964

Posted 2016-01-28T11:55:21.613

Reputation: 31

what do you want to replace it with? – Rico – 2016-01-28T12:04:44.607

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 – 2016-01-28T12:06:07.020

Answers

7

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.

Nichlas H.

Posted 2016-01-28T11:55:21.613

Reputation: 486

2

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.

Brtrnd

Posted 2016-01-28T11:55:21.613

Reputation: 153

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.

Vinayak

Posted 2016-01-28T11:55:21.613

Reputation: 9 310