Multiple Ocurrences on RegExMatch?

Get help with using AutoHotkey and its commands and hotkeys
alesyt0h
Posts: 194
Joined: 28 Jan 2015, 20:37

Multiple Ocurrences on RegExMatch?

10 Jun 2018, 22:54

Hey !!

I have this code

Code: Select all

FileRead, Results, C:\text.txt
RegExMatch(Results, ".*(.*):(.*).*", names)
RegExMatch(Results, ".*K: (.*).*", k)
RegExMatch(Results, ".*K CE: (.*).*", kce)
RegExMatch(Results, ".*Cancelled Date: (.*).*", cancelleddate)
RegExMatch(Results, ".*Days since login: (.*).*", dayssince)
RegExMatch(Results, ".*----------------(.*).*", separator)
together:= names . ","k1 . ","kce1 . ","cancelleddate1 . ","dayssince1 . separator1
msgbox % together
The contents of text.txt

Code: Select all

John:Wick
K: Constructor
K CE: Professional Builder
Cancelled Date: 2017-07-05
Days since login: 2
----------------
Martha:Carreiro
K: Expensive
K CE: Expensive Career
Cancelled Date: 2018-03-01
Days since login: 12

The result is John:Wick,Constructor,Professional Builder,2017-07-05,2

But the Martha Carreiro pack of data is not showed :/

But I want it to continue to the next pack of data to do the same, how can I do it? Thanks!
User avatar
Masonjar13
Posts: 1515
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 02:54

A loop. But a better way would to use a file-reading loop, then have each line processed based on line number (considering they're in a predictable order). You can use your own counting rather than the actual line numbers, so you can skip blank lines and use the separator to reset the count.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
alesyt0h
Posts: 194
Joined: 28 Jan 2015, 20:37

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 04:33

Masonjar13 wrote:A loop. But a better way would to use a file-reading loop, then have each line processed based on line number (considering they're in a predictable order). You can use your own counting rather than the actual line numbers, so you can skip blank lines and use the separator to reset the count.
thanks! but I dont have any clue how to do that :( I tried with a file-reading loop and with that little code to regmatch but it happens the same.. how to ?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 05:15

I tried your script like this:

Code: Select all

Results =
(
John:Wick
K: Constructor
K CE: Professional Builder
Cancelled Date: 2017-07-05
Days since login: 2
----------------
Martha:Carreiro
K: Expensive
K CE: Expensive Career
Cancelled Date: 2018-03-01
Days since login: 12

)

RegExMatch(Results, ".*(.*):(.*).*", names)
RegExMatch(Results, ".*K: (.*).*", k)
RegExMatch(Results, ".*K CE: (.*).*", kce)
RegExMatch(Results, ".*Cancelled Date: (.*).*", cancelleddate)
RegExMatch(Results, ".*Days since login: (.*).*", dayssince)
RegExMatch(Results, ".*----------------(.*).*", separator)
together:= names . ","k1 . ","kce1 . ","cancelleddate1 . ","dayssince1 . separator1
msgbox % together
And I got a result different from yours
The result is John:Wick,Constructor,Professional Builder,2017-07-05,2
My result is

Code: Select all

---------------------------
A_Test.ahk
---------------------------
John:Wick
K: Constructor
K CE: Professional Builder
Cancelled Date: 2017-07-05
Days since login: 2
----------------
Martha:Carreiro
K: Expensive
K CE: Expensive Career
Cancelled Date: 2018-03-01
Days since login: 12
,Expensive
K CE: Expensive Career
Cancelled Date: 2018-03-01
Days since login: 12
,Expensive Career
Cancelled Date: 2018-03-01
Days since login: 12
,2018-03-01
Days since login: 12
,12

Martha:Carreiro
K: Expensive
K CE: Expensive Career
Cancelled Date: 2018-03-01
Days since login: 12

---------------------------
OK   
---------------------------
I think there might be room for improvement in your RegExNeedles, and that needs to be sorted before Looping over the text with all the wrong needles. Just my 2 cents.
alesyt0h
Posts: 194
Joined: 28 Jan 2015, 20:37

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 05:39

That's super ultra weird... are you using AHK_L or something?
maybe is because my variable results is from text file and not inline code ?
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 05:47

I use AHK v1.1.29.01, which was once known as AHK_L.
Do you need to use different version?
Which version do you need, AHK_Basic? aka AHK v1.0.48 ?
alesyt0h
Posts: 194
Joined: 28 Jan 2015, 20:37

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 05:49

Yep, I use the basic
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 05:50

I tested Script also with AHK v1.0.48.05. same result.
swagfag
Posts: 3972
Joined: 11 Jan 2017, 17:59

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 06:14

alesyt0h wrote:Yep, I use the basic
whoooo weeeeee, youd think that couldve been something worth mentioning, like in the very opening sentence of your OP, wouldnt u?

anyway, for anyone else that isnt using basic and is trying to do something similar:

Code: Select all

text := "
(LTrim
	John:Wick
	K: Constructor
	K CE: Professional Builder
	Cancelled Date: 2017-07-05
	Days since login: 2
	----------------
	Martha:Carreiro
	K: Expensive
	K CE: Expensive Career
	Cancelled Date: 2018-03-01
	Days since login: 12
	----------------
	John:Doe
	K: Unknown
	K CE: Unknown Career
	Cancelled Date: 2008-01-01
	Days since login: 1234
)"

; STEP I: split each set of data about a person into chunks
Collection := StrSplit(text, "----------------", "`r`n")

; STEP II: iterate over all chunks of data
People := []
for each, Entry in Collection
{
	
	; STEP III: grab what u need from each chunk
	RegExMatch(Entry, "`am)^(?P<First>[^:]+):(?P<Last>.*)$", Name)
	RegExMatch(Entry, "`am)^K: \K.*$", k)
	RegExMatch(Entry, "`am)^K CE: \K.*$", kce)
	RegExMatch(Entry, "`am)^Cancelled Date: \K.*$", cancelledDate)
	RegExMatch(Entry, "`am)^Days since login: \K.*$", lastLogin)

	; STEP IV: store it all in a manageable data object
	Person := {"firstName": NameFirst
			 , "lastName": NameLast 
			 , "k": k 
			 , "kce": kce 
			 , "cancelledDate": cancelledDate 
			 , "lastLogin": lastLogin}

	; STEP V: store the objects now back in a collection
	People.Push(Person)
}


; STEP VI: there is no step 6
for each, P in People
{
	MsgBox, % Format("
		(LTrim
			Showing info about '{} {}'

			K: {}
			KCE: {}
			Cancelled: {}
			LastLogin: {}			
		)", P.firstName, P.lastName, P.k, P.kce, P.cancelledDate, P.lastLogin)
}
flatwater
Posts: 7
Joined: 28 Dec 2017, 08:21

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 07:34

try

Code: Select all

text=
(
John:Wick
K: Constructor
K CE: Professional Builder
Cancelled Date: 2017-07-05
Days since login: 2
----------------
Martha:Carreiro
K: Expensive
K CE: Expensive Career
Cancelled Date: 2018-03-01
Days since login: 12
)

while pos := RegExMatch(text,"i)(\V+)\v+K: (\V+)\v+K CE: (\V+)\v+Cancelled Date: (\V+)\v+Days since login: (\V+)\v*",m, a_index = 1? 1 : pos + StrLen(m))
	data .= m1 "," m2 "," m3 "," m4 "," m5 "`n"

MsgBox % data
alesyt0h
Posts: 194
Joined: 28 Jan 2015, 20:37

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 10:38

awesome guys !!! thank you so much!!! both examples works perfectly :D

btw swagfag, is that importat to state i use ahk basic ? there are more differences ?
gregster
Posts: 4921
Joined: 30 Sep 2013, 06:48

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 10:49

there are more differences ?
Who knew that in nine years there would be some changes :shock: ??? https://autohotkey.com/docs/AHKL_ChangeLog.htm :wave:
swagfag
Posts: 3972
Joined: 11 Jan 2017, 17:59

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 10:55

you dont think its important to mention youre using a version from a decade ago?
as for whether there are any differences, you can go here and read about them

on an unrelated note: i like ahk basics icon better, basic left, latest ahkl right
Image
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 11:32

@swagfag: You prefer the AutoHotkey Basic icons do you?
change AutoHotkey's 4 systray icons - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 23#p208123
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
swagfag
Posts: 3972
Joined: 11 Jan 2017, 17:59

Re: Multiple Ocurrences on RegExMatch?

11 Jun 2018, 12:01

ive replaced them with reshacker already but thanks anyway

Return to “Ask For Help”

Who is online

Users browsing this forum: mikeyww and 59 guests