If a Web Page Changes Format, the Data-Extracting Regular Expressions (RegEx) May Need Updating—Fixing the SynonymLookup.ahk Script
When writing a blog, I tend to use certain words over and over again. While rereading early versions, these redundant words jump out at me. Not only do they point out my limited vocabulary, but the repetitions tend to render my blogs a little more starchy and boring. That’s why I often resort to my always-loaded SynonymLookup.ahk script. This app saves time while making me look a little smarter.


After I discover a duplicated word, I highlight it, then hit the Ctrl+Alt+L Hotkey combination. A menu of possible replacements pops up. I click on the one that best fits my intent and the new term immediately displaces the original text. I habitually use this script.
When the SynonymLookup.ahk Script Breaks

Over the life of the script, I’ve encountered the menu shown at right a couple of times. This menu pops up whenever the script downloads and scans the source code 10 times without getting a RegEx hit—usually the result of code changes made by the source page Webmaster.
Note: If you see the above pop-up, click the App Broken! Check for Update? menu item to access the Free AutoHotkey Scripts page in search of a possible script update. Since I use SynonymLookup regularly, I usually notice the problem within a week or less and modify the RegEx—making it operational again. (If you discover the script not working and I haven’t posted an update, please contact me.)
For more information on how this script works, see “The SynonymLookup.ahk Web Data-Driven App Fails (AutoHotkey Adjustments).” To learn more about using Web pages to extract data for your AutoHotkey apps, see “Chapter Eight: A Simple Way to Find Out Where in the World That IP Address Is Located” of the book, A Beginner’s Guide to Using Regular Expressions in AutoHotkey
Fixing the Regular Expressions (RegEx)
When I run into this problem, I open the target Web page (click the bold word at the beginning of the menu) and access the source HTML code (right-click and select “View page source” in Google). Then I locate the primary list of synonyms—looking for a code pattern. In the current page, I found that the words “targetTerm” and “targetSlug” surround each possibility:

I merely needed to alter the previous RegEx search expression in the SynonymLookup.ahk script’s RegExMatch() function to include those boundary words :
SynPos := RegExMatch(SynPage,"""targetTerm"":""(.*?)"",""targetSlug""",Synonym,NewSynPos)
This change made the script operational again. In fact, most to the menus now include even more possibilities than the previous version—although I do see the occasional odd placement of items on the menu. (I can’t take credit for the increase in synonym options. That’s purely a function of how The Webmasters rewrote the code.)
Note: To produce a lone double-quote ("
) for use in the RegExMatch() function and other expressions, escape double-quotation marks ("
) by preceding each with another double-quote (""
).
Checking for Antonyms
I needed to change how the antonym check works. (The script places a yellow caution sign () before each antonym menu item—mostly.) Usually, the terms “Synonyms” or “Antonyms” appear somewhere between the old word location (SysPos) and the new word location (NewSynPos). For speed, I extracted that string and searched for the term “Antonym” and “Synonym”:
AntonymCheck := SubStr(SynPage, NewSynPos , SynPos-NewSynPos)
If InStr(AntonymCheck,"Antonyms") {
AntonymPos := 1
}
If InStr(AntonymCheck,"Synonyms") {
AntonymPos := 0
}
The script uses a true AntonymPos value to add the caution sign to likely antonym menu items:
If (AntonymPos = 1)
Menu, Synonym, Icon, %Synonym1%, %A_Windir%\system32\SHELL32.dll, 78
This antonym check works pretty well—although occasionally, due to inconsistencies in the source code, it mislabels a word or two. I spent a little bit of time looking at those issues, but decided that the result offered enough information to get the job done without spending too much time perfecting it. If you need the precise information (with examples), clicking on the bold term at the beginning of the menu takes you to the Web page.
Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)

This post was proofread by Grammarly
(Any other mistakes are all mine.)
(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)
Find my AutoHotkey books at ComputorEdge E-Books!
Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!
Jack,
Check out this regex
https://www.autohotkey.com/boards/viewtopic.php?p=360564#p360564
I have to deal with so much junk that needs to be cleaned out doing my work with routers.
Thought you’d be interested.
gosub AssignString ; put in subroutine so it’s at the bottom out of the way
StrArr := StrSplit(String, “!”, “`n`r”)
for each, Input in StrArr
{
RegExMatch(Input, “(description\V+).*ip address ([\d\.]+)”, Match)
Output := “! ” . Match1 . “`nping ” . (InStr(Input, “vrf”) ? “vrf vpn-crs ” : “”) . Match2
MsgBox, % Output
}
return
AssignString:
String =
(
interface GigabitEthernet0/0/1.101
description link outermongolia9-hub Gi0/0/1/8.101 – – management
encapsulation dot1Q 101
ip address 172.25.241.45 255.255.255.252
no ip proxy-arp
!
interface GigabitEthernet0/0/1.102
description link outermongolia9-hub Gi0/0/1/8.102 – – vpn-crs
encapsulation dot1Q 102
vrf forwarding vpn-crs
ip address 207.171.113.157 255.255.255.252
no ip proxy-arp
!
interface GigabitEthernet0/0/1.103
description link outermongolia9-hub Gi0/0/1/8.103 – – vpn-voice
encapsulation dot1Q 103
vrf forwarding vpn-voice
ip address 10.255.225.1 255.255.255.252
no ip proxy-arp
!
interface GigabitEthernet0/0/1.104
description link outermongolia9-hub Gi0/0/1/8.104 – – vpn-video
encapsulation dot1Q 104
vrf forwarding vpn-video
ip address 172.20.120.5 255.255.255.252
no ip proxy-arp
!
interface GigabitEthernet0/0/1.105
description link outermongolia9-hub Gi0/0/1/8.105 – – ng911
encapsulation dot1Q 105
vrf forwarding vpn-ng911
ip address 172.16.32.169 255.255.255.252
no ip proxy-arp
!
interface GigabitEthernet0/0/1.106
description link outermongolia9-hub Gi0/0/1/8.106 – – vpn-courts
encapsulation dot1Q 106
vrf forwarding vpn-courts
ip address 172.31.252.1 255.255.255.252
no ip proxy-arp
!
interface GigabitEthernet0/0/1.116
description link outermongolia-hub gi0/0/3.116 – – vpn-crs
encapsulation dot1Q 116
ip vrf forwarding vpn-crs
ip address 10.10.114.73 255.255.255.252
no ip proxy-arp
bfd interval 600 min_rx 600 multiplier 3
)
return
LikeLike