How to find all e-mail addresses in string/variable via regex?

And, of course, as alternatives to Perl, we could generalize the same kind of thing in AppleScript:

-- uniqueSortedMatchesInText :: Regex -> String -> [String]
on uniqueSortedMatchesInText(rgx, s)
    sort(nub(map(my headDef, regexMatches(rgx, s))))
end uniqueSortedMatchesInText

or in JavaScript for Automation:

// uniqueSortedMatchesInText :: Regex -> String -> [String]
const uniqueSortedMatchesInText = (rgx, s) =>
    sort(nub(map(headDef, regexMatches(rgx, s))));

All emails in selected text.kmmacros (27.5 KB)

1 Like