Split lines in Emeditor

75 views Asked by At

I have a line of data: first name, last name, mail1, mail2, mail3. I need to retrieve the line:

first name, last name, mail1
first name, last name, mail2
first name, last name, mail3

Tried different ways of combining, splitting lines. I can't find the right solution

1

There are 1 answers

0
Marijn On

Because e-mail adresses don't contain commas you can use regular expression search and replace. Search for three sequences of not-comma, separated by comma, at the end of the line. Also match whatever comes before these three sequences. Now, match group 1 is the first name and last name, and match group 2,3,4 are mail1, mail2 and mail3 respectively. Then you can replace by 1,2 [newline] 1,3 [newline] 1,4 [newline].

In regex syntax:

Search

(.*), ([^,]+), ([^,]+), ([^,]+)$

Replace

\1, \2\n\1, \3\n\1, \4

Explanation of search pattern:

( open group
. any character
* repeated an arbitrary number of times
) close group
,  literal comma and space
( open group
[ open character class
^ not
, comma
] close character class
+ repeat at least once
) close group
i.e., [^,]+ means sequence of non-commas
...etc....
$ end of line

Explanation of replace pattern:

\1 match group 1
,  literal comma and literal space
\2 match group 2
\n newline
\1 match group 1
...etc...