AutoHotkey Webinar-02/2019 Working session

In today’s webinar we helped troubleshoot some examples from attendees.

Video Hour 1: High-level overview: Hour 1:
Video Hour 2: Q&A: Hour 2

The script showcase was Lexikos’ DebugVars which can be found here

During the webinar Dale shared a script which would help him select the “upper-level” of a key by long-pressing the key.  Cap’n Odin rewrote it (twice) and you can see the final version here.

If you have any suggestions for upcoming webinars, please let us know!

RegEx 111) Ignore Whitespace in AutoHotkey Regular Expression

Ignore Whitespace in AutoHotkey Regular ExpressionAutoHotkey Merchandise-White Stress ballLong 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!

#SingleInstance, Force
#NoEnv
Browser_Forward::Reload
Browser_Back::
response=
(
{"items":[{"id":3866967518001,"name":"TechDays","referenceId":null,"playsTotal":null},{"id":3869639371001,"name":"Sensitivity and Selectivity in Low Power RF","referenceId":"0_4f50771k","playsTotal":null},{"id":3869653908001,"name":"Low Power RF Developer - Wireless Glue Networks Inc.","referenceId":"0_wraewmky","playsTotal":null},{"id":3869704547001,"name":"The Babelfish may Soon be Science Fact","referenceId":"0_m73cr9uf","playsTotal":null},{"id":3873942948001,"name":"Xilinx FPGA 向け電源設計ツール","referenceId":"0_w7mv8jwm","playsTotal":null},{"id":3880705798001,"name":"FORAPPROVAL_EELive_Demo20_DLP_FORAPPROVAL","referenceId":null,"playsTotal":2},{"id":3880723945001,"name":"EELive_Demo22_Low_Power_Vision","referenceId":null,"playsTotal":1},{"id":3881779779001,"name":"UCC28711 10mW 소모 전력 데모","referenceId":"0_8ejutfdv","playsTotal":null},{"id":3870946516001,"name":"LM5113 Enhancement Mode GaN FET Half-Bridge Driver Demo","referenceId":"0_wuof80ce","playsTotal":301},{"id":3907785832001,"name":"C6A8168 C6-Integra Processor Overview (Standard - Small)","referenceId":null,"playsTotal":null}],"page_number":0,"page_size":10,"total_count":4574}
)

RegExMatch(response, "xO)^" ;x=Ignore Whitespace in AutoHotkey Regular Expression, O store in object
	. "(?:\{""items"":\[)" ;remove early part not wanted-not capture using ?:
	. "(?P<json_Videos>.*)" ; grabbing json of videos
	. "(?:\],""page_number"":(?P<Page_Numb>\d{1,5}),)"  ;Page number looping through
	. "(?:""page_size"":(?P<Vids_Per_Page>\d{1,3}),)"  ;videos per page
	. "(?:""total_count"":(?P<Total_Numb_Vids>\d{1,5})" ;Total count of videos
	. "\})", Vids) ;closing out regexmatch

MsgBox,,total numb vids, % vids.Total_Numb_Vids
MsgBox,,json for videos, % vids.json_Videos
MsgBox,,vids per page, % vids.Vids_Per_Page
MsgBox,,Page_Numb, % vids.Page_Numb

Ignore Whitespace in AutoHotkey Regular Expression

RegEx 110- Example using AutoHotkey Regular Expression on naming convention

AutoHotkey Regular Expression on naming conventionAutoHotkey Merchandise-White Stress ballI’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.

Video demonstrating AutoHotkey Regular Expression on naming convention

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 video

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