Ditto icon indicating copy to clipboard operation
Ditto copied to clipboard

How can I extract email addresses from a text when pasting

Open xiaobq opened this issue 3 years ago • 4 comments

The text is copied from Outlook with texts like below.

Vinas, abby <[email protected]>; Vinas, tom <[email protected]>; West, Edmond <[email protected]>;

now I want to get the email addresses from this text only when pasting, how can I do it?

xiaobq avatar Jun 24 '21 09:06 xiaobq

Did you ever figure this out?

imthenachoman avatar Oct 18 '23 16:10 imthenachoman

this can be done with an on paste script. options - general - advanced - on paste scripts

`var oldString = clip.GetAsciiString(); var allEmail = ""; var email = ""; var inEmail = false; for(var i = 0; i < oldString.size(); ++i) { if(oldString[i] == '>') { if(allEmail != "") { allEmail += "\r\n" } allEmail += email inEmail = false; email = ""; } if(inEmail == true) { email += oldString[i]; } if(oldString[i] == '<') { inEmail = true; } } clip.SetAsciiString(allEmail); return

image

image

sabrogden avatar Oct 19 '23 23:10 sabrogden

This will only work if email address is inside a < and >. I have use cases where you might have other formats. My hope was to match on email regex and extract that way. It does not appear that Ditto and/or ChaiScript lets you do that? I can't make sense of the ChaiScript documentation.

imthenachoman avatar Oct 21 '23 02:10 imthenachoman

@sabrogden Any thoughts on how I can extract email addresses when they aren't surrounded by < or >?

My thought was to, somehow, use non email valid characters as a way to chunk up an input string. Thoughts?

imthenachoman avatar Oct 24 '23 02:10 imthenachoman