Using a Regular Expression (RegEx) to Find a URL and not an email address

Find a URL and not an email addressA subscriber reached out to me (after trying for a few hours) for some help on creating a Regular Expression to pull-out URLs from text.  Specifically not including email addresses.  Since he gave it a solid try I wanted to help him out.  I did a google search and found this post which had the RegEx pattern for finding a URL and not an email address.  I then took the pattern and put it on Regular Expressions 101 to make sure it would work in AutoHotkey.   After that I adapted it to AutoHotkey code (see below) using RegExMatch.

Find a URL and not an email address

Code to Find a URL and not an email address

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Lorem ipsum [email protected] dolor sit amet, (555)555.8957 consectetuer adipiscing elit. @recruiting  lorem ipsum
dolor sit elit.
dolor sit elit.
Pos:=1 ;set starting point

Loop, {
  ;Regex Pattern for URLs borrowed from
  Found_Pos:=RegExMatch(Text,"i)((http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&:\/~+#-]*[\[email protected]?^=%&\/~+#-])?)",Obj,Pos)
  Pos:=Found_Pos+(StrLen(obj)+1) ;Set next start position
  URLs.=obj "`r" ;add to emails variable
  If not OBJ ;If not found break Loop
MsgBox % URLs


Example Webservice / API call- Yelp and working through oAuth2

In our API webinar we discussed how oAuth2 works however there is no better way to explain it than to actually work through an example!  In the below video & code I demonstrate how to access Yelp to perform the “handshake” with oAuth1 and receive the oAuth2 authentication.  I also demonstrate using a named Regular Expression to isolate the returned token.


;***********API call to get Authorization Token*******************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("POST",EndPoint . QueryString)
data:=HTTP.ResponseText ;~ MsgBox,,title, % response
RegExMatch(data,".*access_token\x22:\s\x22(?<Token>.*?)\x22.*",Yelp_) ;RegEx to grab token
;~  MsgBox % Yelp_token


QueryString:=QueryString_Builder({"term":"restaurants","location":"Coppell, TX","categories":"chicken_wings"})

;***********API call to yelp with Credentials*******************
HTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HTTP.Open("GET", EndPoint . queryString)
HTTP.SetRequestHeader("Authorization","Bearer " . Yelp_token)
Response_Data:=HTTP.ResponseText ;~ MsgBox,,title, % response
SciTE_Output(Response_Data) ;Text,Clear=1,LineBreak=1,Exit=0

;***********QueryString Builders*******************
for key, value in kvp
  queryString.=((A_Index="1")?(url "?"):("&")) key "=" value
return queryString

Video walking through the API example / oAuth2 process




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 to extract emails with a Regular Expression that I demonstrate in the video

Extract email addresses via Regular Expression in AutoHotkey