RegExMatch help Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
XMCQCX
Posts: 230
Joined: 14 Oct 2020, 23:44

RegExMatch help

Post by XMCQCX » 12 Aug 2022, 17:52

Hi,

I'm trying to match the choice of a pipe-delimited list of choices of a ComboBox store in an INI file.

Code: Select all

Apple|Orange|Cherry||Kiwi

Code: Select all

Apple||Orange|Cherry|Kiwi
How to get Cherry or Apple in these strings.

Code: Select all

(\^|\|)(.*)\|\|
I tried this one and a lot of things without success. Any help will be much appreciated. Thanks

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

Re: RegExMatch help

Post by mikeyww » 12 Aug 2022, 18:17

Code: Select all

For each, list in ["Apple|Orange|Cherry||Kiwi", "Apple||Orange|Cherry|Kiwi"] {
 RegExMatch(list, "([^|]+)\|\|", m)
 MsgBox, 64, Choice, %m1%
}

sofista
Posts: 650
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: RegExMatch help  Topic is solved

Post by sofista » 12 Aug 2022, 18:35

Or:

Code: Select all

data := "
(
Apple|Orange|Cherry||Kiwi
Apple||Orange|Cherry|Kiwi
)"

For k, v in StrSplit(data, "`n")
	MsgBox, % (m, RegExMatch(v, "\w+(?=\|\|)", m))

XMCQCX
Posts: 230
Joined: 14 Oct 2020, 23:44

Re: RegExMatch help

Post by XMCQCX » 12 Aug 2022, 19:24

mikeyww wrote:
sofista wrote:
Thank you for the help guys. Your help is always greatly appreciated !

XMCQCX
Posts: 230
Joined: 14 Oct 2020, 23:44

Re: RegExMatch help

Post by XMCQCX » 12 Aug 2022, 20:10

mikeyww wrote:
12 Aug 2022, 18:17

Code: Select all

For each, list in ["Apple|Orange|Cherry||Kiwi", "Apple||Orange|Cherry|Kiwi"] {
 RegExMatch(list, "([^|]+)\|\|", m)
 MsgBox, 64, Choice, %m1%
}
Thanks a lot, mikeyww. Where I can find a list of the Built-in Variables for the for-loop command, each, LIST; each, LINE. I have never seen that in the documentation.

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

Re: RegExMatch help

Post by mikeyww » 12 Aug 2022, 20:37

It's because they are not built in. You can use whatever variables you want for the key & value. I used each for the key, and list for the value. Sofista used k for the key, and v for the value.

Explained: For

XMCQCX
Posts: 230
Joined: 14 Oct 2020, 23:44

Re: RegExMatch help

Post by XMCQCX » 12 Aug 2022, 20:48

mikeyww wrote:
12 Aug 2022, 20:37
It's because they are not built in. You can use whatever variables you want for the key & value. I used each for the key, and list for the value. Sofista used k for the key, and v for the value.

Explained: For
Ok, thanks for the clarification.

Post Reply

Return to “Ask for Help (v1)”