A subscriber of my YouTube channel had an issue with using RegExMatch. I decided it was better to walk through the process in a video than to just provide the code. 🙂 As mentioned in the video I highly recommend Jack Dunning’s Regular Expressions AutoHotkey book. Continue reading
Tag: pattern matching
AutoHotkey webinar on Regular Expressions- Learn some great RegEx Tips!
This AHK Webinar focused on Regular Expressions.
AutoHotkey Webinar Videos
Video of Hour One
Video of Hour two
Content from AutoHotkey Webinar
- “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:
- 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
- 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
- * 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
- RegEx Match
- RegEx Replace
- Quick Reference
- Forum thread for RegEx Questions
- RegEx tutorial by sinkfaze
- RegEx tutorial videos by Joe Glines
Tools Built in AutoHotkey
- Expressive by Alguimist
- Regex Tester by Robert Ryan
- RegEx Tester by goralf
- LiveRegexTester by njciancio
Websites to test dynamic code
Additional Resources
- RegEx Buddy
- RegEx Coach
- Lyna.com course Using Regular Expressions by Kevin Skoglund
- Introduction to Regular Expressions in AutoHotkey By Jack Dunning
- Mastering Regular Expressions by Jeffrey Friedl
Check out more AutoHotkey webinars
Sign-up for future ones here
RegEx 111) How to Ignore Whitespace in AutoHotkey Regular Expression
Long Regular Expressions can be very difficult to read and revise when you come back to it later. Using the X) option allows you to Ignore Whitespace in AutoHotkey Regular Expression and insert comments as well as spread out your RegEx over multiple lines.
Below is the example code I use to ignore the whitespace in AutoHotkey RegEx which is demonstrated in the video below. It is a great way to make your code easier to read & maintain. It may take a few months until you revisit your RegEx but, when you do, you’ll thank me for it!
Ignore Whitespace in AutoHotkey Regular Expression
RegEx 110- Example using AutoHotkey Regular Expression on naming convention
I’ve found the best way to learn RegEx is to actually play with it. For that reason I’m making a few videos that will demonstrate actual use-cases. In this example I demonstrate applying an AutoHotkey Regular Expression on naming convention. As I show in this video, there are a ton of different ways you can write a Regular Expression that will capture what you need. There isn’t a “right” & “wrong” way, just make sure what you use is reliable and makes sense to you.