Search code examples
regexnotepad++

add a zero after regex each lines


I have a list like following:

ABCCC
4,322,469
FSFFSDF
4,322,000
GFGFGBFG
444,567
ABCFD
DFGHJKK
00000

Now I want to add zero after consecutive lines that start with a character like following:

ABCCC
4,322,469
FSFFSDF
4,322,000
GFGFGBFG
444,567
ABCFD
0
DFGHJKK
0
00000

following regex can select consecutive lines that start with a character:

^[A-Za-z].*\R([A-Za-z].*)$

I tried following regex but not working for me:

Find: ^[A-Za-z].*\R([A-Za-z].*)$  
Replace: \0\n0  

where is my regex problem?


Solution

  • Works in Notepad.

    If you want to place a 0 after every one in a block of consecutive Alpha lines, use the \G construct, and a look ahead.

    (?m)(?:^[A-Za-z].*\R(?=[A-Za-z])|(?<!\A)\G[A-Za-z].*\R)\K

    https://regex101.com/r/1inhnS/1

    Overview

    (?m)
    (?:
       ^ 
       [A-Za-z] .* \R 
       (?= [A-Za-z] )
     | 
       (?<! \A )
       \G 
       [A-Za-z] .* \R 
    )
    \K