RegEx 106-Use Named subpatterns in AutoHotkey Regular Expressions

Named subpatterns in AutoHotkey Regular ExpressionsA white stress ball with the green AutoHotkey logo being held in a hand, with a laptop keyboard blurred in the backgroundUsing Regular Expressions in AutoHotkey is awesome!  On more complex expressions, I like to use Named subpatterns in AutoHotkey Regular Expressions to, automatically, store the results in named variables which indicate what they represent.

I typically get my RegEx working properly then I go back and change the pattern to using a named subpattern.  For instance if the following was your RegEx that you got working:

(\w\w\w)/(\d\d)/(\d\d\d\d) I would go back and adapt it to:

“(?P<Mon>\w\w\w)/(?P<Day>\d\d)/(?P<Year>\d\d\d\d)”

text=
(
I'm recording this on 11/12/2016
01/06/2016
)
RegExMatch(text,".*(?P<Mon>\d\d)/(?P<Day>\d\d)/(?P<Year>\d\d\d\d)",Date_)
MsgBox % Date_Mon  "`n" Date_Day  "`n" Date_Year

 

Video demonstrating how to create Named subpatterns in AutoHotkey Regular Expressions

Four colleagues seated at a meeting table, with a green AutoHotkey water bottle in the center

RegEx 105- Simplify RegEx with escapes in AutoHotkey Regular Expressions

Woman holding a green-and-white Schüttelbecher-style bottle outdoors, with a label reading Schüttelbecher on the front Wait, let me correct that toescapes in AutoHotkey Regular ExpressionsUsing RegEx to identify text patterns is an awesome skill-set to have.  In the below tutorial we review some of the shortcuts /escapes in AutoHotkey Regular Expressions.  These can make your code much more reader-friendly and easier to maintain.

Here’s a cheat-sheet for some of the more popular escapes:

  • \w =word character
  • \d = digit
  • \s =white space (tab, space, etc)
  • \b = word boundary

Remember, for each of the above, you can select the inverse of them simply by capitalizing the letter.

Demo video showing how to use Shortcuts / Escapes in AutoHotkey Regular Expressions

AutoHotkey Merchandise-White Stress ball

RegEx 104-Using Anchors in AutoHotkey Regular Expressions

Anchors in AutoHotkey Regular ExpressionsA white stress ball with the green AutoHotkey logo being held in a hand, with a laptop keyboard blurred in the backgroundRegular Expressions are amazing but can also slow-down your AutoHotkey script.  Being able to us Anchors in AutoHotkey Regular Expressions are great ways to minimize false matches and speed-up your pattern matching!  The best part is they are very easy to use, just begin your search with a ^ to anchor your search at the beginning or use the $ to anchor it to the end of the line.   Also don’t forget to enable multi-line as 90% of the time you’re using Anchors you’ll be wanting to treat each line as a separate entity.

Video demonstrating using Anchors in AutoHotkey Regular Expressions

Woman holding a white water bottle with a green AutoHotkey logo and green cap, sitting on grass