Regex help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chriskeith21
Posts: 16
Joined: 03 Nov 2019, 22:54

Regex help

06 Jan 2020, 22:22

Hello, I'm trying to extract information within my windowtitle. I had it working using Substr but that only worked when the desired outcome was 4 digits. But I found not all of them are. For example, all of my windowtitles within this program end with an ID that is in parenthesis. I tried the code below and it worked for 4 digit ids but I found that some IDs are more or less digits. So how do I use regex to pull only the characters inside the parenthesis from my wintitle? Thanks for your help.

WinGetTitle, V_WinTitA, A
V_facid := SubStr(V_WinTitA, -4, 4)
Send, %V_facid%
chriskeith21
Posts: 16
Joined: 03 Nov 2019, 22:54

Re: Regex help

06 Jan 2020, 23:04

Caveat...I just realized all of the wintitles have two sets of parentheses so I'm trying to extract the text from the second set of parentheses.
example dfjakfdjkajfkfkjajfd(12345) aadfafadjkjlskjdfkj (6789)

I need to copy 6789 to a variable.
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Regex help

06 Jan 2020, 23:26

try:

Code: Select all

V_WinTitA := " dfjakfdjkajfkfkjajfd(12345) aadfafadjkjlskjdfkj (6789)"
regexmatch(V_WinTitA, "\((\d+)\)$",match)
msgbox, % match1
14.3 & 1.3.7
chriskeith21
Posts: 16
Joined: 03 Nov 2019, 22:54

Re: Regex help

06 Jan 2020, 23:36

Thanks. If that long number with the parentheses is constantly changing, what would I replace that with in the code?
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Regex help

06 Jan 2020, 23:43

Code: Select all

WinGetTitle, V_WinTitA, A
regexmatch(V_WinTitA, "\((\d+)\)$",match)
send, % match1
14.3 & 1.3.7
chriskeith21
Posts: 16
Joined: 03 Nov 2019, 22:54

Re: Regex help

07 Jan 2020, 00:04

Thanks so much. I got it to work when I used the long made up variable but when I use the second example, I can't get it to work. I'm sure it's user error. I even tried to force activate the program's window. I'll keep at it. Thanks for your time.

WinActivate, ahk_class ThunderRT6MDIForm
WinGetTitle, V_WinTitA, A
Sleep, 500
regexmatch(V_WinTitA, "\((\d+)\)$",match)
Sleep, 500
msgbox, % match1
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Regex help

07 Jan 2020, 00:10

I would help if you run:

Code: Select all

V_WinTitA := " dfjakfdjkajfkfkjajfd(12345) aadfafadjkjlskjdfkj (6789)"
regexmatch(V_WinTitA, "\((\d+)\)$",match)
msgbox, % match1
,change the V_WinTitA variable to the possible combinations of the wintitle and report on the results. The above should return 6789.
14.3 & 1.3.7
chriskeith21
Posts: 16
Joined: 03 Nov 2019, 22:54

Re: Regex help

07 Jan 2020, 01:11

Thanks so much. You're a lifesaver.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, jaka1, RussF and 308 guests