Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Why match not capturing some part ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Sun Oct 01, 2023 10:17 am    Post subject: Why match not capturing some part ? Reply with quote

I try retrieve some startTime and endTime values.
The values are 25/09/2023--10:20:30 and 02/10/2023--20:30:40 respectively.
When I print them the output values are correct (see image included).

But when I try to use match in the following it does not capture the seconds but captures all the others (see image included)

Code:
local day2, month2, year2, hour2, min2, sec2 = startTime:match("(.-)/(.-)/(.-)%-%-(.-):(.-):(.-)")
local day3, month3, year3, hour3, min3, sec3 = endTime:match("(.-)/(.-)/(.-)%-%-(.-):(.-):(.-)")

print(startTime)
print(endTime)
print(day2, month2, year2, hour2, min2, sec2)
print(day3, month3, year3, hour3, min3, sec3)


What is the reason for this? It captures the other parts before the seconds just fine. Confused...help.



Capture.JPG
 Description:
 Filesize:  17.64 KB
 Viewed:  1183 Time(s)

Capture.JPG


Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4652

PostPosted: Sun Oct 01, 2023 11:00 am    Post subject: Reply with quote

The pattern `.-` matches the least amount of characters it can.

The part matching minutes is surrounded by colons. That means `.-` must match everything until the next colon.
For seconds, there is no such limitation. It must start at a colon, but it's not required to end anywhere in particular. Given that, the least amount of characters `.-` can match is 0.
e.g.:
Code:
assert(('1234'):match'%d*' == '1234')
assert(('1234'):match'%d-' == '')

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 35

Joined: 16 Feb 2017
Posts: 1476

PostPosted: Sun Oct 01, 2023 12:38 pm    Post subject: Reply with quote

@ParkurPenguen captured the parsing and selection parameters correctly.

Yes, restricted parsing and reading: "(.-)", full line or spanning reading: "(.*)"
You don't want to use this ( "(.*)" ) between lines, maybe used at the last read point.

Of course, there are more practical ways and symbols to read and parse these directories in Lua.

However, for beginners, I am covering the most ordinary expressions in order to see what it does and how to apply it.

Here's a fix that reads the seconds;

Code:
startTime = "25/09/2023--10:20:30"
endTime = "02/10/2023--20:30:40"

local day2, month2, year2, hour2, min2, sec2 = startTime:match("(.-)/(.-)/(.-)%-%-(.-):(.-):(.*)")
local day3, month3, year3, hour3, min3, sec3 = endTime:match("(.-)/(.-)/(.-)%-%-(.-):(.-):(.*)")

print(startTime)
print(endTime)
print(day2, month2, year2, hour2, min2, sec2)
print(day3, month3, year3, hour3, min3, sec3)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Bit Byte
Advanced Cheater
Reputation: 0

Joined: 28 Nov 2022
Posts: 62

PostPosted: Sun Oct 01, 2023 11:36 pm    Post subject: Reply with quote

I had already tried using (.*) before posting here but still had problems.
If there is data in cell after the end date then that is also captured and then then the seconds part is not calculated properly.

Code:
local day2, month2, year2, hour2, min2, sec2 = startTime:match("(.-)/(.-)/(.-)%-%-(.-):(.-):(.*)")
local day3, month3, year3, hour3, min3, sec3 = endTime:match("(.-)/(.-)/(.-)%-%-(.-):(.-):(.*)")
END_TIME = os.time({year=tonumber(year3),month=tonumber(month3),day=tonumber(day3),hour=tonumber(hour3),min=tonumber(min3),sec=tonumber(sec3)})

print(day2, month2, year2, hour2, min2, sec2)
print(day3, month3, year3, hour3, min3, sec3)
print(END_TIME)


See image of data table and output with and without data in cell after end date.
With data in cell after end date gives wrong result for END_TIME as the seconds part is not captured properly.



Capture3.JPG
 Description:
 Filesize:  16.79 KB
 Viewed:  1085 Time(s)

Capture3.JPG



Capture4.JPG
 Description:
 Filesize:  16.14 KB
 Viewed:  1085 Time(s)

Capture4.JPG



Capture2.JPG
 Description:
 Filesize:  28.35 KB
 Viewed:  1085 Time(s)

Capture2.JPG


Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 150

Joined: 06 Jul 2014
Posts: 4652

PostPosted: Mon Oct 02, 2023 1:06 am    Post subject: Reply with quote

If you don't want to match everything, then don't write a pattern that matches everything.
Character classes exist in Lua. i.e. '%d'
https://www.lua.org/manual/5.3/manual.html#6.4.1

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites