Extract email address from text with Regular Expression in AutoHotkey

Extract email addressRegular Expressions are incredibly helpful for day-to-day tasks!  In this short video I demonstrate how easy it is to use a Regular Expression (RegEx) in AutoHotkey to extract email addresses from text.  The first half of the video shows how I use it to parse the haystack listed in the script.  The second half of the video I make a minor tweak and adapt it to work with any program that you can copy text to the clipboard.

Below is the code I demonstrate in the video

Haystack =
hello [email protected] more text
worked and [email protected]
did too and [email protected]
this also works [email protected]
432 432 [email protected] 43432
;Send ^c ;uncomment to use in any program
;Haystack:=Clipboard ;uncomment to use in any program

Pos:=1 ;set starting position
loop, {
Pos:=Pos_Found+StrLen(mail)+1 ;move location to new position + mail lenght+ 1
IfEqual,mail,,break ;Break loop if no mail found
mails.=mail "`n"
MsgBox % mails


Extract email addresses via Regular Expression in AutoHotkey

RegEx 108-Return your match in AutoHotkey Regular Expressions match object

AutoHotkey Regular Expressions match objectNeed to get additional information about your RegExMatch?  Why not return a AutoHotkey Regular Expressions match object?  Having your data returned in an object allows for some great information like: Length, location, name of subpattern, etc.  With AHK  you can use the O) option to store the matches into an AutoHotkey object.  The below video walks through how to do it and gives you a clear example how to access it once it is created.

Create and access an AutoHotkey Regular Expressions match object

Here is the code demonstrated in the videoAutoHotkey Merchandise-White Stress ball

str:="Hello, world   how are you doing"  ;define String

MsgBox % "     value: " obj.Word "`r"
 	   . "  value:  " obj.Value["Word"]  "`r"
	   . "position: " obj.Pos["Word"]  "`r"
	   . "  Length: " obj.len["Word"]  "`r"
	   . "    Name: " obj.Name["Word"]  "`r"
	   . "  Count:  " obj.Count()  "`r"

MsgBox % "     value: " obj.delim "`r"
 	   . "  value:  " obj.Value["Delim"]  "`r"
	   . "position: " obj.Pos["delim"]  "`r"
	   . "  Length: " obj.len["delim"]  "`r"
	   . "    Name: " obj.Name["delim"]  "`r"
	   . "  Count:  " obj.Count()  "`r"