Page 1 of 1

Regexmatch & Grep issue

Posted: 27 Aug 2022, 13:53
by maitresin
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

Re: Regexmatch & Grep issue

Posted: 27 Aug 2022, 14:55
by boiler
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.

Re: Regexmatch & Grep issue

Posted: 27 Aug 2022, 15:14
by maitresin
Perfect! thanks you!