A Regex problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

A Regex problem

12 Jan 2022, 11:49

I need to get user names as i highlited. But ı cant figure out how to.

Here is the link. Thank you very much.
Last edited by murataygun on 12 Jan 2022, 15:40, edited 1 time in total.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: A Regex problem

12 Jan 2022, 11:51

For the first instance: (?<=\()[^)]*

For the second instance: (?<= : ).*(?= - )


Are they going to be different and you need to get both? Or are you just looking to get one or the other?
Last edited by boiler on 12 Jan 2022, 11:54, edited 1 time in total.
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: A Regex problem

12 Jan 2022, 11:54

boiler wrote:
12 Jan 2022, 11:51
For the first instance: (?<=\()[^)]*
But it should match with the other one which has no parentheses around too. It should match both lines.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: A Regex problem

12 Jan 2022, 11:59

Actually, the problem with getting the second name is a problem if we are just trying to isolate that it is preceded with a " : " and followed by a " - ", because that occur elsewhere and would also capture the IP address shown earlier. Will the second instance always be preceded by "Kullanıcı : "?

You need to show some other cases so that we can see what will always be in place. Even "Kullanıcı : " occurs more than once.
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: A Regex problem

12 Jan 2022, 12:08

boiler wrote:
12 Jan 2022, 11:59
Actually, the problem with getting the second name is a problem if we are just trying to isolate that it is preceded with a " : " and followed by a " - ", because that occur elsewhere and would also capture the IP address shown earlier. Will the second instance always be preceded by "Kullanıcı : "?

You need to show some other cases so that we can see what will always be in place. Even "Kullanıcı : " occurs more than once.
Yes. "Kullanıcı" will allways be there.
Last edited by murataygun on 12 Jan 2022, 15:40, edited 1 time in total.
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: A Regex problem

12 Jan 2022, 12:10

Updated example
Last edited by murataygun on 12 Jan 2022, 15:40, edited 1 time in total.
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: A Regex problem

12 Jan 2022, 12:11

boiler wrote:
12 Jan 2022, 11:59
Actually, the problem with getting the second name is a problem if we are just trying to isolate that it is preceded with a " : " and followed by a " - ", because that occur elsewhere and would also capture the IP address shown earlier. Will the second instance always be preceded by "Kullanıcı : "?

You need to show some other cases so that we can see what will always be in place. Even "Kullanıcı : " occurs more than once.
Btw thank you for your time :angel:
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: A Regex problem

12 Jan 2022, 12:13

This matches both as two capturing groups: (\([^)]*).*Kullanıcı : (.*) -

You need to have the "s" (single line) option selected.

It works with your latest example to. Make sure the "s" option is selected on that one too.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: A Regex problem

12 Jan 2022, 12:31

Correction: \(([^)]*).*Kullanıcı : (.*) -

The previous version had an error that included the open parenthesis in the first result.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: A Regex problem

12 Jan 2022, 12:33

AHK demonstration:

Code: Select all

Text =
(
Pil Ölçer
Network Flyout
 POLİKLİNİK MUAYENE - Kullanıcı : TEM01(BİROL ÖZKAYNAK) - Frm : POLIKLINIK_MUAYENE_ACIL1024 - Ver : 1.0.1 - IP : 10.45.64.58 - Stok : ACIL POLIKLINIĞI
POLİKLİNİK MUAYENE - Kullanıcı : HK1131(MURAT AYGÜN) - Frm : POLIKLINIK_MUAYENE_ACIL1024 - Ver : 1.0.1 - IP : 10.45.64.58 - Stok : ACIL POLIKLINIĞI
ETIKET
VAKA GELİŞİ KAYDI...

Prokalca.exe
tetkik GUI
Poliklinik Defteri - Vers: 1.0.1.520 - Kullanıcı : BİROL ÖZKAYNAK - Stok : ACIL POLIKLINIĞI
Poliklinik Defteri - Vers: 1.0.1.520 - Kullanıcı : MURAT AYGÜN - Stok : ACIL POLIKLINIĞI
ETIKET
)
RegExMatch(Text, "\(([^)]*).*Kullanıcı : (.*) -", Name)
MsgBox, % "Name 1: " Name1 "`nName 2: " Name2
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: A Regex problem

12 Jan 2022, 12:34

Am i missing something
Last edited by murataygun on 12 Jan 2022, 15:41, edited 1 time in total.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: A Regex problem

12 Jan 2022, 12:37

Yes, now you've shown a case that doesn't match either of the other two. Now the second name isn't followed by " - ".

You can't show certain cases and then wonder why something that's a different format doesn't also work. If I change it to make it match that one as well, you could easily show another different case where it wouldn't. Do you understand why what's surrounding the name is important? That's how it figures out where to grab it from. It can't magically know where the name starts and ends.
murataygun
Posts: 104
Joined: 07 Aug 2015, 15:53

Re: A Regex problem

12 Jan 2022, 13:07

boiler wrote:
12 Jan 2022, 12:37
Now the second name isn't followed by " - "
But it is followed by " - "

Sorry to bother you but I'm getting windows titles and searching user names on each line. I got 3 different titles which has user names in it. I should collect all.


This covers number 2 and 3.

Code: Select all

(?<= : ).*(?= - )
This covers number 1.

Code: Select all

(?<=\()[^)]*
Maybe i should check the beginning of the title and use regex code for it accordingly.

Thanks for these codes.
Last edited by murataygun on 12 Jan 2022, 15:41, edited 1 time in total.
User avatar
boiler
Posts: 17387
Joined: 21 Dec 2014, 02:44

Re: A Regex problem

12 Jan 2022, 13:10

I see now. You're right. Easily addressed by changing the last quantifier to be ungreedy:
\(([^)]*).*Kullanıcı : (.*?) -

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Kodakku and 393 guests