• Intro to AutoHotkey HotStrings with AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Intro to DOS & AutoHotkey AutoHotkey FAQ2

RegEx 109- 3 ways to Escape double quotes in AutoHotkey Regular Expression

double quotes in AutoHotkey Regular ExpressionAutoHotkey Merchandise-White Stress ballMuch of the syntax in AutoHotkey RegEx is straightforward.  Having said that when trying to include double quotes () in my pattern I regularly had difficulties.  In the following video  I demonstrate three separate ways you can escape double quotes in AutoHotkey Regular Expressions.

Here’s a video showing how to handle double quotes in AutoHotkey Regular Expression

And this is the syntax I used escaping  quotes in AutoHotkey Regular Expressions in making the videoAutoHotkey Bottle 3

OuterHTML=
(
<select name="st" id="st">
<option selected="selected" value="20">All results</option>
<option value="13">1 day</option>
)

;***********Storing in variable*******************
;~ RegEx_pattern=selected" value="(?P<Value>.*?)">All results.*?<option value="(?P<Value2>\d+).*? ;done this way- don't need to escape "
;~ RegExMatch(OuterHTML,RegEx_pattern, Sel_)
;~ MsgBox % "first way`r`r" Sel_Value a_tab Sel_Value2

;***********using \x22  *******************
;~ RegExMatch(OuterHTML,"selected\x22 value=\x22(?P<Value>.*?)\x22>All results.*?<option value=\x22(?P<Value2>\d+)\x22.*?", Sel_)
;~ MsgBox % "second way `r`r" Sel_Value a_tab Sel_Value2

;***********repeated ""*******************
RegExMatch(OuterHTML,"selected"" value=""(?P<Value>.*?)"">All results.*?<option value=""(?P<Value2>\d+)"".*?", Sel_)
MsgBox % "third way `r`r" Sel_Value a_tab Sel_Value2

 

RegEx 108-Return your match in AutoHotkey Regular Expressions match object

AutoHotkey Regular Expressions match objectAutoHotkey Bottle 1Need to get additional information about your RegExMatch?  Why not return a AutoHotkey Regular Expressions match object?  Having your data returned in an object allows for some great information like: Length, location, name of subpattern, etc.  With AHK  you can use the O) option to store the matches into an AutoHotkey object.  The below video walks through how to do it and gives you a clear example how to access it once it is created.

Create and access an AutoHotkey Regular Expressions match object

Here is the code demonstrated in the video

RegEx 107- Using POSIX in AutoHotkey Regular Expressions

POSIX in AutoHotkey Regular ExpressionsAutoHotkey Bottle 2Once you get used to the RegEx symbols it is pretty easy to follow however, those not familiar with it, will often be perplexed by what it is doing.  I will sometimes use POSIX in AutoHotkey Regular Expressions to help layman read my code.  While it is easier to read, it does add considerable length to the expression (but don’t confuse length with the speed of it working.  I doubt there is a correlation in this case)

POSIX (pronounced PAH-zihcks) is an acronym for Portable Operating System Interface from UNIX

Demo video using POSIX in AutoHotkey Regular Expressions

AutoHotkey Bottle 3

RegEx 106-Use Named subpatterns in AutoHotkey Regular Expressions

Named subpatterns in AutoHotkey Regular ExpressionsSquishy Ball 2Using 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

AutoHotkey Bottle 1