regex in notepad++ — looking to modify text on line 2 dependant on a certain character string being present on the previous line (line 1))
I have text of the below format that I wish to modify using regex and notepad++.
Format of text:
16.232.39.195
dwdwevevveeve
148.92.235.232
49.58.203.107
130.221.168.79
vfeevvewdwdqwdq
2.170.109.98
254.250.64.253
10.102.107.236
155.146.118.222
ntyrovgmnfewijw
47.80.127.125
ewfwfmbbrmbve
26.232.99.92
10.0.46.127
229.154.77.234
35.15.165.153
fewomwvmvvm
157.27.74.183
78.244.169.225
114.7.107.67
xfevwwf
13.118.248.99
wefwfwwf
116.102.16.22
wfgheegfwf
22.4.118.222
61.205.56.191
Explanation of how I want to modify the above data format using regex and notepadd++ :
The above data format is a list of IP addresses. You will note that on the line after some of the IP addresses, there is a text string, and after some other IP addresses, there is no text string. For the IP addresses that currently don’t have a text string in the following line, I want to insert a text string. Let’s say for illustrative purposes I want to insert the text string ‘ABC123’ in the line after each IP address that currently isn’t followed by a text string. If I could do this successfully, my data would be modified to look like the below:
16.232.39.195
dwdwevevveeve
148.92.235.232
ABC123
49.58.203.107
ABC123
130.221.168.79
vfeevvewdwdqwdq
2.170.109.98
ABC123
254.250.64.253
ABC123
10.102.107.236
ABC123
155.146.118.222
ntyrovgmnfewijw
47.80.127.125
ewfwfmbbrmbve
26.232.99.92
ABC123
10.0.46.127
ABC123
229.154.77.234
ABC123
35.15.165.153
fewomwvmvvm
157.27.74.183
ABC123
78.244.169.225
ABC123
114.7.107.67
xfevwwf
13.118.248.99
wefwfwwf
116.102.16.22
wfgheegfwf
22.4.118.222
ABC123
61.205.56.191
ABC123
So in algorithmic terms I want to do something like:
for IP address on line A:
if string on line B = IP address
then insert a new line after line A that contains the string 'ABC123'
elseif string on line B = character string
then do nothing
repeat the above process for the next IP address in the document.
I know that if all of the text were on a single line, I would be able to solve the problem with the below regex / notepad++ method:
Find: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})
replace with: \1 ABC123 \2
But it is the fact that each IP address and text string is on a separate line that I am not sure how to solve.
Any advice on the best way to solve this would be greatly appreciated.
Read more here: Source link