StringRegExp Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maskeli
Posts: 33
Joined: 09 May 2020, 05:06

StringRegExp

15 Apr 2021, 14:33

in autoit :

Code: Select all

$keys = StringRegExp("gun15 ay4 yil2021", "gun(\d+) ay(\d+) yil(\d+)", $STR_REGEXPARRAYMATCH)
;$keys[0] = 15
;$keys[1] = 4
;$keys[2] = 2021
is there a function in autohotkey like this ?
I looked at RegExMatch () function but couldn't do it correctly

Code: Select all

RegExMatch("O)abcXYZ123", "abc(.*)123", SubPat)
msgbox, % SubPat.Value(1)
; i want SubPat.Value(1) = 1
how can i do this ? thanks
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StringRegExp

15 Apr 2021, 15:05

The O) goes in the needle, not in the haystack:

Code: Select all

RegExMatch("abcXYZ123", "O)abc(.*)123", SubPat)
SubPat.Value(1) will contain XYZ, not 1, but it will still evaluate as true since it contains a string instead of a null.
AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: StringRegExp

15 Apr 2021, 15:07

Maybe you can use named subpatterns, the documentation is not that helpfull for this topic.
This example should be able to help you:

Code: Select all

RegExMatch("gun15 ay4 yil2021", "gun(?P<Gun>\d+)\say(?P<Ay>\d+)\syil(?P<Yil>\d+)", SubPat_)
msgbox, % SubPat_Gun "`n" SubPat_Ay "`n" SubPat_Yil
maskeli
Posts: 33
Joined: 09 May 2020, 05:06

Re: StringRegExp

15 Apr 2021, 15:16

AHK_user wrote:
15 Apr 2021, 15:07
Maybe you can use named subpatterns, the documentation is not that helpfull for this topic.
This example should be able to help you:

Code: Select all

RegExMatch("gun15 ay4 yil2021", "gun(?P<Gun>\d+)\say(?P<Ay>\d+)\syil(?P<Yil>\d+)", SubPat_)
msgbox, % SubPat_Gun "`n" SubPat_Ay "`n" SubPat_Yil
this code works but I don't understand how it works. Does it have a less confusing shape?
by the way thanks my friend
maskeli
Posts: 33
Joined: 09 May 2020, 05:06

Re: StringRegExp

15 Apr 2021, 15:18

@AHK_user

this code works, but I don't quite understand how it works. It contains things I don't know. Is there a simpler version?
maskeli
Posts: 33
Joined: 09 May 2020, 05:06

Re: StringRegExp

15 Apr 2021, 15:29

RegExMatch("abcXYZ123", "O)abc(.*)123", SubPat)
msgbox, % SubPat.Value(1)

also this code works well. thanks for all answers ^^
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StringRegExp  Topic is solved

15 Apr 2021, 15:37

Here are couple ways to do it similar to your AutoIt code. The first one using an object, the second one without an object.

Code: Select all

RegExMatch("gun15 ay4 yil2021", "O)gun(\d+) ay(\d+) yil(\d+)", SubPat)
MsgBox, % SubPat.Value(1) "`n" SubPat.Value(2) "`n" SubPat.Value(3)

RegExMatch("gun15 ay4 yil2021", "gun(\d+) ay(\d+) yil(\d+)", SubPat)
MsgBox, % SubPat1 "`n" SubPat2 "`n" SubPat3
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: StringRegExp

15 Apr 2021, 15:41

(use the updated version of the above post as I removed some not-needed stuff and fixed a typo)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 216 guests