Use this javascript, I get the result
david(aboy@gmail.com)
jack(bboy@gmail.com)
lily(cboy@gmail.com)
The result is three lines.
Maybe not three lines, maybe four lines.
I want save aboy@gmail.com in variable1.
save bboy@gmail.com in variable2.
save cboy@gmail.com in variable3.
Is there any methods ?
RegEx is probably the best way to separate a string.
just search for:
(^.*)(\n.*)(\n.*)(\n.*)
(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:
\((.*)\)\n.*\((.*)\)\n.*\((.*)\)
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?
2 Likes
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 https://wiki.keyboardmaestro.com/collection/Substrings_In