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%
Regex help
-
- Posts: 16
- Joined: 03 Nov 2019, 22:54
-
- Posts: 16
- Joined: 03 Nov 2019, 22:54
Re: Regex help
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.
example dfjakfdjkajfkfkjajfd(12345) aadfafadjkjlskjdfkj (6789)
I need to copy 6789 to a variable.
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Regex help
try:
Code: Select all
V_WinTitA := " dfjakfdjkajfkfkjajfd(12345) aadfafadjkjlskjdfkj (6789)"
regexmatch(V_WinTitA, "\((\d+)\)$",match)
msgbox, % match1
14.3 & 1.3.7
-
- Posts: 16
- Joined: 03 Nov 2019, 22:54
Re: Regex help
Thanks. If that long number with the parentheses is constantly changing, what would I replace that with in the code?
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Regex help
Code: Select all
WinGetTitle, V_WinTitA, A
regexmatch(V_WinTitA, "\((\d+)\)$",match)
send, % match1
14.3 & 1.3.7
-
- Posts: 16
- Joined: 03 Nov 2019, 22:54
Re: Regex help
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
WinActivate, ahk_class ThunderRT6MDIForm
WinGetTitle, V_WinTitA, A
Sleep, 500
regexmatch(V_WinTitA, "\((\d+)\)$",match)
Sleep, 500
msgbox, % match1
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Regex help
I would help if you run:
,change the V_WinTitA variable to the possible combinations of the wintitle and report on the results. The above should return 6789.
Code: Select all
V_WinTitA := " dfjakfdjkajfkfkjajfd(12345) aadfafadjkjlskjdfkj (6789)"
regexmatch(V_WinTitA, "\((\d+)\)$",match)
msgbox, % match1
14.3 & 1.3.7
-
- Posts: 16
- Joined: 03 Nov 2019, 22:54
Re: Regex help
Thanks so much. You're a lifesaver.