AutoHotkey Webinar- Parsing plain text with AutoHotkey

Video Hour 1: High-level overview:AutoHotkey Webinar

In the first hour of our AutoHotkey webinar we demonstrated Quick Access Popup from our guest speaker Jean Lalonde.  It is an amazingly customizable tool that allows you to have what you want at your fingertips!

Here is an abbreviated list of some of the great features:

  1. Create shortcuts to folders, programs, files, links, Snippets, special folders, etc.
  2. Easily create Hotkeys for above shortcuts
  3. Works with most Open/Save dialog boxes
  4. Integrated with most file managers (Windows Explorer, Directory Opus, Total Commander, etc.)
  5. The tool itself is highly customizable
  6. Have “shared” sections as well as individual ones
  7. Organize your menu into folders & sub-folders
  8. Customize Menu/GUI shortcut with an icon (that makes sense to you)
  9. Available in 10 languages

You can watch a short overview video here or get a deeper dive here.  Jean was kind enough to walk me through his tool in this video.

We then talked about what a “text file” is and frequent sources of them (Export from programs, sever logs, emails, etc).  We also briefly discussed what is File / Character Encoding & why are there frequent problems with it (this is a very deep topic which we could have spent days discussing!)

Also discussed  what a “flat file” is and how they are different than:

  • Multi-row files
  • Relational files
  • XML and JSON files

We then shared some of the frequently used built-in commands and functions for parsing text in AutoHotkey.

Then we got into various custom-built in libraries and functions

Then our guest speaker, Jean, took over walking us through some examples of common problems with AutoHotkey LoopParse command

The library is pretty cool and here are some of the main functions available:

  • CSV2Collection() – Transfer the content of a CSV file to a collection of objects.
  • Collection2CSV() – Transfer the selected fields from a collection of objects to a CSV file.
  • Collection2Fixed() – Transfer the selected fields from a collection of objects to a fixed-width file.
  • Collection2HTML() – Builds an HTML file based on a template where variables are replaced with content.
  • Collection2XML() – Builds an XML file from the content of the collection.
  • Collection2ListView() – Transfer the selected fields from a collection of objects to ListView.
  • ListView2Collection() – Transfer the selected lines of the selected columns of a ListView to a collection of objects.

ObjCSV Examples:  Here are the files Jean worked through.

  • SIMPLE CSV FILE – COMA DELIMITED (TheBeatles-coma.txt)
  • SIMPLE CSV FILE – TAB DELIMITED – ISSUE #1 (TheBeatles-tab.txt)
  • MULTI-LINE CSV FILE – COMA DELIMITED – ISSUE #2 (TheBeatles-Lyrics.txt)

Jean then gave us a review of how to use his ObjCSV library

  • Example using ObjCSV_CSV2Collection
  • SIMPLE CSV FILE – COMA DELIMITED (TheBeatles-coma.txt)
  • SIMPLE CSV FILE – TAB DELIMITED – ISSUE #1 SOLVED (TheBeatles-tab.txt)
  • MULTI-LINE CSV FILE – COMA DELIMITED – ISSUE #2 SOLVED (TheBeatles-Lyrics.txt)
  • PROGRESS BAR WITH LARGE CSV FILE – SEMI-COLON DELIMITED (LargeFile-semicolon.txt)
  • CUSTOM HEADER – SIMPLE CSV FILE – COMA DELIMITED (TheBeatles-coma.txt)
  • GUI Example using Collection2ListView
  • SAVING WITH DIFFERENT DELIMITER using ObjCSV_Collection2CSV
  • EXPORT HTML Example using ObjCSV_Collection2HTML

Wrapping up the first section we then saw a peak at CSVBuddy

CSVBuddy Examples

  • Reading large file with auto-detection
  • Editing field names, re-order or select fields
  • Saving options
  • Saving file with multi-line content converted to single-line (Excel-ready)
  • Reverting the single-line file to multi-line (for example, after manipulation in Excel)

Video Hour 2: Q&A:

In the second hour we discussed various issues working with text data as well as took a deeper look into Quick Access Popup.

Near the end of the time Capn Odin shared a Trie script he’s been working on.  You can check out the script on the forum

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

 

Extract email addresses via Regular Expression in AutoHotkey

Extract email addresses with Regular Expression in AutoHotkey

RegEx 112 – Using RegExReplace in AutoHotkey to manipulate date structure

RegExReplace in AutoHotkeyIn this tutorial I use RegExReplace in AutoHotkey to move the days to the beginning of the date format and months to the middle.  While it is pretty straight-forward, I managed to forget to add something to my script which forced me to trouble-shoot.  I talked through a bit of the process of how I typically will work on a Regular Expression.

I think most people working in Regular Expressions don’t get it right the first time. They often need to make little tweaks to get it right.  😉  Keep at it!

Video demonstrating using RegExReplace in AutoHotkey to manipulate dates

RegEx 112 RegExReplace in AutoHotkey- Example moving around Charchaters

AutoHotkey webinar on Regular Expressions- Learn some great RegEx Tips!

This AHK Webinar focused on Regular Expressions.

AutoHotkey Webinar Videos

AutoHotkey webinar

Video of Hour One

Video of Hour two

Content from AutoHotkey Webinar

What are Regular Expressions?

  • “Symbols that describe a text pattern”
  • Pattern matching- Chances are extremely high that you’re familiar with this.
    • 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

When to use RegEx vs. other functions like StrReplace(), InStr()

  • When Haystack is smaller- probably doesn’t matter
  • StrReplace() and InStr() are faster than RegEx but simpler

General rule-of-thumb:  Use RegEx when your pattern is more complex

RegExMatch vs. RegEx Replace

There is definitely overlap between the two tools however here is a high-level view of their “niche” areas & important their differences:

RegExMatch()

  • Tool for finding, saving & extracting specific matches
  • Once your match is found, RegExMatch has done it’s job and stops processing. To continue you need to restart beginning where your last match was found
  • Does NOT affect original data
  • Returns found position
  • O) Match pattern can be returned as an object/pseudo array for easy access

RegExReplace()

  • Modification tool allows you to change (re-order/structure, swap out) your data
  • Does not stop after finding first match. Unless otherwise stipulated it proceeds through the entire haystack
  • Returns Newstring:= (altered) string

Common / Helpful RegEx Options

  • m) Multiline (treats each line as separate text)
  • U) Ungreedy (stops at first match)
  • x) Ignore whitespace (great for multiline RegEx)
  • C) Auto-callout mode (help show where you are in your Expression)
  • O) (in RegExMatch) returns match in object

Quantifiers

  • * 0 or more times
  • ? 0 or 1 times
  • + 1 or more times
  • {N} exactly N times
  • {N,} N or more times
  • {N,M} N through M times

Characters Needing Escape

  • \ . * ? + [ { | ( ) ^ $”

Ranges

  • [1-5], [a-e]

Special Characters

  • ^ Start of Line
  • $ End of Line
  • . Any character

Escapes

  • \d  Digit              \D   Non-digit
  • \s Whitespace    \S    Non-whitespace
  • \w “Word“          \W Non-“Word”
  • \n  New Line       \t  Tab
  • \r  Line Return   \b  Boundary
  • \QLiteral\E
  • \x  where x is Hex  \x22=“

Regular Expression Resources

AutoHotkey Help

Tools Built in AutoHotkey

Websites to test dynamic code

Additional Resources

Check out more AutoHotkey webinars

Sign-up for future ones here