• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

RegEx 101-Intro to Regular Expressions in AutoHotkey- Pattern matching made easy!

Regular Expressions in AutoHotkey

Regular Expressions in AutoHotkey (RegEx) are an amazing tool to have in your toolbox!  The simplest definition I have found of Reg Ex are: “Symbols that describe a Text Pattern”.  It is more than likely that you’ve used them in the past.  Here are a few examples where you have probably used them:

  • Using * or ? when looking for a file in Windows Explorer
  • Validate format ( email, phone number, zip code, two-letter state abbreviation)
  • Search & replace text in files
  • Count # of times pattern exists
  • Find duplicate words

In this intro video I give a high-level overview using Regular Expressions in AutoHotkey.  The video demonstrates pattern matching by using Expressive by Alguimist.  There are several other tools specifically written in / for AutoHotkey however this one is pretty simple and does 99% of what you’ll need.  You also might use RegEx101 for aiding your pattern matching.

RegEx 101- Regular Expressions in AutoHotkey

Using MS Word to select email addresses and paste

select email

Select Email in MS Word

Microsoft Word has a very powerful search / replace feature (and a bit easier for most to play with than a Regular Expression).  One of the things I use it for is to select email addresses from a a document.

The following needs to be added to the search field: [A-Za-z0-9-._]{2,}[@]{1}[A-Za-z0-9-._][A-Za-z0-9-._][@]1[A-Za-z0-9-._]

Don’t forget to turn on Wildcards!

Using a strong Naming Convention & RegEx are keys to automating metrics!

naming conventions

Naming Convention and Regular Expression (RegEx)

Having a strong naming convention can make reporting on your metrics a breeze when you use a regular expression to break out-decrypt the naming scheme. This video shows how easy it is for us to extract: Region, Language, Campaign Type, etc. from our campaign names by using a regular expression. It also points out that there is no need to be stuck with poor acronyms for your reporting.

In my above example I use AutoHotKey with Excel.  If you add the function, Excel can do RegEx itself however (for some crazy reason) it isn’t built into it.

Text file explorer-Determine file headers & delimiters without opening file

Text file explorer

Text File ExplorerText file explorer

I often work with large text files in which the file extension (.txt, .dat, .csv, .tab) doesn’t always indicate what type of delimiter is used in the file.  When the file is small, I’ll typically just “pop” it open in SciTE / Notepad.  Large files (anything over 20 megs) often take a fair amount of time to read and very large files ( a gig or more) will often run into out of memory issues.

On top of wanting to know the delimiter, I also frequently want to know what fields / Headers are in the file.   This normally means I have to open it in a text editor or Excel and review.  I wrote the below Text File Explorer in AutoHotkey script to simplify the above.  I can highlight a file from Windows Explorer and quickly detect the type of delimiter plus display headers if I care to.

Text file explorer AutoHotkey code:


Here’s a video demonstrating the usage of the Text file Explorer