Regexmatch without limit for number of keywords

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Regexmatch without limit for number of keywords

Post by milkygirl90 » 17 Oct 2021, 17:25

1. How do I define separate keywords using 𝗲𝗶𝘁𝗵𝗲𝗿 comma, space, or new line return? In this context, is it true that I can only choose one?
2. How do I make it such that each keyword must be ≤ 5 letters (no numbers), and I can have as many keywords input as I want?
3. How do I loop through both keywords and the URLs at the same time as per comments?

My attempt below.

Thank you.

Code: Select all

InputBox, Keywords, Search Keyword(s), Enter keyword(s).  Separate multiple keywords with comma, space, or new line return.,, 390, 135
if ErrorLevel  ; The user pressed Cancel.
    return
RegExMatch(Keywords, "((^[a-zA-Z]{1,5})$),(^[a-zA-Z]{1,5})$),(^[a-zA-Z]{1,5})$)", Keyword) { ; match 5 letters only 
; not sure how to loop the keywords through multiple URLs here, and if there's a better way to code this portion

URL1 := "https://www.test.com/search/" . keyword1 . 
URL2 := "https://www.anothersite.com/search/" . keyword1 . 
Run, %URL1%
Run, %URL2%
WinWaitActive, ahk_exe chrome.exe
return

Code: Select all

sample input
A
C
MSI
GPI
Z
CRSD
GAWFQ

Rohwedder
Posts: 7612
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Regexmatch without limit for number of keywords

Post by Rohwedder » 18 Oct 2021, 02:13

Hallo,
try (without: each keyword must be ≤ 5 letters):

Code: Select all

Hotkey, IfWinActive, Search Keyword(s)
Loop,% 10
{ ;(no numbers!)
	Hotkey,% "Numpad" A_Index-1, Beep
	Hotkey,% A_Index-1, Beep
}
InputBox, Keywords, Search Keyword(s), Enter keyword(s) (no numbers!)
. Separate multiple keywords with comma`, space`, or new line return.,, 390, 150
if ErrorLevel  ; The user pressed Cancel.
    return
Keywords := StrSplit(Keywords, [",", " ", "|"])
For No, Keyword in Keywords
	MsgBox,, Keyword,% No ". Keyword = " Keyword, 1
Return
Beep:
SoundBeep, 4000, 500
Return
#IfWinActive, Search Keyword(s)
Enter::|
NumpadEnter::|
#If

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Regexmatch without limit for number of keywords

Post by milkygirl90 » 18 Oct 2021, 04:18

I amended the code slightly to make it more understandable (for myself), and the key is stored correctly, but the URL doesn't append my key. can't be wrong syntax? 😕

Code: Select all

Keywords := StrSplit(Keywords, [",", " ", "|"])
For No, Keyword in Keywords{
	if RegExMatch(Keyword, "(^[a-zA-Z]{1,5})$")  ; match 5 characters only 
key := Keyword, %No%
msgbox, % key
Run, "https://www.def.com/search/" . key . 
Run, "https://www.abc.co/search/" . key . 
;	MsgBox,, Keyword,% No ". Keyword = " Keyword, 1
}

Rohwedder
Posts: 7612
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Regexmatch without limit for number of keywords

Post by Rohwedder » 18 Oct 2021, 04:50

perhaps:

Code: Select all

Keywords := StrSplit(Keywords, [",", " ", "|"])
For No, Keyword in Keywords
{
	if !RegExMatch(Keyword, "^[a-zA-Z]{1,5}$")  ; match 1-5 characters only
		Continue
	MsgBox, https://www.def.com/search/%Keyword%
	Run, https://www.def.com/search/%Keyword%
	MsgBox, https://www.abc.co/search/%Keyword%
	Run, https://www.abc.co/search/%Keyword%
}

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Regexmatch without limit for number of keywords

Post by milkygirl90 » 18 Oct 2021, 17:24

thank you so much!!

Post Reply

Return to “Ask for Help (v1)”