How to separate three lines to get three variables

Use this javascript, I get the result

The result is three lines.
Maybe not three lines, maybe four lines.
I want save in variable1.
save in variable2.
save in variable3.
Is there any methods ?

RegEx is probably the best way to separate a string.

just search for:
(repeat (\n.*) for as many groups you like to save) and set the variable names

Quick example draft attached

Separate String Using RegEx.kmmacros (16.0 KB)

1 Like

Oh, probably something like this as you only want the email not the whole line:

1 Like

why do you want to assign each line to a KM variable?
How will you use these variables?

I generally find it easier to just use a For Each action with a lines collection that is either in ONE variable, or from a file.

It looks like to me that each line is just an email address.
What do you want to do with each address?


You should also pay attention to the warning:


If you are going to use Open a File Folder or Application action to open an application, make sure you select the Finder as the application to open it, otherwise you may end up opening Google Chrome as a document in some other application (eg an archiving application).

Alternatively, use the Activate a Specific Application action.

1 Like

Oh this is cool, did not know that setting in the for each action. That's a much better approach than mine.
I thought it is odd that there is no global setting in the regex action, but I guess this should be done with a For Each as well, like described in the wiki