Regexmatch & Grep issue

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

Regexmatch & Grep issue

27 Aug 2022, 13:53

Hello,

I need help with the below synthax
"s)2022-08-25,(.*)," should not return only 2.050000 ?

What should be the correct synthax to return only the in between value? anything between "2022-08-25," and ","

see code

Code: Select all

FileRead, FileRead1, file.txt
	g:=grep(fileread1, "s)2022-08-25,(.*),")
	for i, v in g
	{
	result1 := v.1
	msgbox, %result1%
	}
	exitapp
	
	grep(haystack, needle)
{
    a:=[], match := "", pos := 1
    while pos:=RegExMatch(haystack, needle, match, pos+StrLen(match))
        a[A_Index]:= {"match": match, 1: match1}
    Return a
}
return
	
;	msgbox show
;	2.050000,2.200000,1.970000,2.190000,2.190000
;	2022-08-26,2.180000,2.220000,2.000000,2.010000,2.010000
	
;	file.txt content
;	2022-08-25,2.050000,2.200000,1.970000,2.190000,2.190000
;	2022-08-26,2.180000,2.220000,2.000000,2.010000,2.010000
User avatar
boiler
Posts: 17215
Joined: 21 Dec 2014, 02:44

Re: Regexmatch & Grep issue

27 Aug 2022, 14:55

Change (.*) to (.*?) to make it ungreedy. Yours is a match, grabbing everything it can and still end with a comma. You want it to grab the least it can and still end with a comma.
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

Re: Regexmatch & Grep issue

27 Aug 2022, 15:14

Perfect! thanks you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: sachalamp and 212 guests