rafa_2k1
rafa_2k1

Reputation: 35

How do i insert a line in front of a previous line using regex on notepad++?

For example, I would like to following list:

E|MG000|HIST|062575|08012019|062575|MG003
L|22WBM3|1|1871.1
E|MG000|HIST|020590|31012019|020590|MG003
L|10B771D015|-4|8.488
E|MG000|HIST|062575|21022019|062575|MG003
L|22WBM3|-1|1871.1

to look like this:

E|MG000|HIST|062575|08012019|062575|MG003 - L|22WBM3|1|1871.1
E|MG000|HIST|020590|31012019|020590|MG003 - L|10B771D015|-4|8.488
E|MG000|HIST|062575|21022019|062575|MG003 - L|22WBM3|-1|1871.1

Upvotes: 0

Views: 243

Answers (2)

Toto
Toto

Reputation: 91375

  • Ctrl+H
  • Find what: \R(?=L)
  • Replace with: - (space hyphen space)
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

\R          # any kind of linebreak
(?=         # positive lookahead, make sure we have after:
    L         # letter L
)           # end lookahead

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Upvotes: 0

user13469682
user13469682

Reputation:

Try (?m)^(E\|(?:(?!L\|).)+)\s+^(L\|.*(?:\r?\n)?)
Replace $1 - $2

demo

Upvotes: 1

Related Questions