Using if else with RegExMatch Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Using if else with RegExMatch

Post by jarhead » 28 Jan 2022, 13:46

I'm trying to detect a value on my clipboard that is formatted either like 123-R-20210128-9999 or 123456789 (9 digits). If I run the two RegExMatch scripts below separately, they work (with the correct pattern for each on the clipboard).

When I combine them in an if else, the first one (the if statement) always fails with the correct pattern (123-R-20210128-9999) on the clipboard. The second one works with 123456789 on my clipboard. I'm assuming since the second one is looking for nine digits it is somehow interfering with the last portion of the regex statement in the if statement → \d+$

I'm going to add a MsgBox if the clipboard does not contain either value but cannot get this portion to work. Thanks!

Code: Select all

if (regexmatch(Clipboard, "^\d{3}-[A-Z]{1}-\d{8}-\d+$"))
{
	gcnum := Clipboard
	type := "Title"
}

else (regexmatch(Clipboard, "^\d{9}$"))
{
	gcnum := Clipboard
	type := "SSN"
}

url := "https://mysite.com/_api/Web/Lists/GetByTitle('This Title')/items?$select=id,Title,Name,Facility,NewColumn1,Urgent_x003f_&$expand=Facility/Full_x0020_Facility&$filter=Facility/Full_x0020_Facility ne '' and startswith(" . type . ", '" . gcnum . "')"	

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Using if else with RegExMatch  Topic is solved

Post by mikeyww » 28 Jan 2022, 14:06

RegExMatch itself returns a number. It can also return a variable or pseudoarray if you specify one as a function parameter. Without checking either (e.g., "Else If..."), nothing much happens.

jarhead
Posts: 149
Joined: 09 Sep 2020, 12:43

Re: Using if else with RegExMatch

Post by jarhead » 28 Jan 2022, 15:06

mikeyww wrote:
28 Jan 2022, 14:06
RegExMatch itself returns a number. It can also return a variable or pseudoarray if you specify one as a function parameter. Without checking either (e.g., "Else If..."), nothing much happens.
What a silly mistake... else if works. Thanks mikeyww! :headwall:

Rikk03
Posts: 192
Joined: 12 Oct 2020, 02:44

Re: Using if else with RegExMatch

Post by Rikk03 » 15 Dec 2023, 03:25

@mikeyww
Can you provide an example?

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Using if else with RegExMatch

Post by mikeyww » 15 Dec 2023, 06:37


Post Reply

Return to “Ask for Help (v1)”