 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Bit Byte Advanced Cheater
Reputation: 0
Joined: 28 Nov 2022 Posts: 62
|
Posted: Sun Oct 01, 2023 10:17 am Post subject: Why match not capturing some part ? |
|
|
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.
Description: |
|
Filesize: |
17.64 KB |
Viewed: |
1183 Time(s) |

|
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 150
Joined: 06 Jul 2014 Posts: 4652
|
Posted: Sun Oct 01, 2023 11:00 am Post subject: |
|
|
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 |
|
 |
AylinCE Grandmaster Cheater Supreme
Reputation: 35
Joined: 16 Feb 2017 Posts: 1476
|
Posted: Sun Oct 01, 2023 12:38 pm Post subject: |
|
|
@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) |
_________________
|
|
Back to top |
|
 |
Bit Byte Advanced Cheater
Reputation: 0
Joined: 28 Nov 2022 Posts: 62
|
Posted: Sun Oct 01, 2023 11:36 pm Post subject: |
|
|
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.
Description: |
|
Filesize: |
16.79 KB |
Viewed: |
1085 Time(s) |

|
Description: |
|
Filesize: |
16.14 KB |
Viewed: |
1085 Time(s) |

|
Description: |
|
Filesize: |
28.35 KB |
Viewed: |
1085 Time(s) |

|
|
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 150
Joined: 06 Jul 2014 Posts: 4652
|
Posted: Mon Oct 02, 2023 1:06 am Post subject: |
|
|
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 |
|
 |
|
|
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
|
|