1

I have a big .txt file, I need to modified this file in NotePad++, find a line start with "1H" and add a number "2" at position 10 for this line. for example

1A 3333333333333
1B 4444444444444
1H 5555555555555
1A 6666666666666
1B 7777777777777
1H 8888888888888

I want the line in 1H to be modified by adding 2 at position 10. How can I do that in NotePad++?

I don't know how to combine the ^(1H) and ^(.{10}) together for the search part.

chris85
  • 23,846
  • 7
  • 34
  • 51
Kan
  • 11
  • 1

1 Answers1

3
Find what:    ^(1H.{7})(.)
Replace with: \12

This pattern requires a line that starts with 1H and 7 other characters. The parentheses make sure this 9-character string is stored as the first group. Then the next character, which is in the tenth position, is stored as the second group.

The full match is then replaced by group 1 (\1) and the character '2' to get the desired result.

1A 3333333333333
1B 4444444444444
1H 5555552555555
1A 6666666666666
1B 7777777777777
1H 8888882888888
Junuxx
  • 14,011
  • 5
  • 41
  • 71
  • Tested and works correctly for me. I think you can only have 9 capture groups (1-9). – Junuxx Feb 21 '17 at 22:17
  • 1
    @chris85: Apparently, at least in N++, /n can only access 1-9. To access capture group numbers >=10, you use $n. See also [this question](https://stackoverflow.com/questions/10907440/how-do-i-group-regular-expressions-past-the-9th-backreference). – Junuxx Feb 21 '17 at 22:25
  • Thanks, this is great! – Kan Feb 22 '17 at 16:58