Reputation: 88
So unfortunately Javascript doesn't support the \K
token in regex, I'm searching for a way around this.
My Problem:
I have this regexp:
Total statistics:\s+\K\d+
which should give me the "driven meters" of my lawn mower from a log string like this:
{"logSystem":[[2019,4,26,10,37,0,44872,"Battery Charge Started! 17.0°C
21.05Volt","#000099","normal"],[2019,4,26,10,37,0,44871,"Total statistics:
334418m, 23862min, blade on time: 21289min","#2E2EFE","bold"],
[2019,4,26,10,37,0,44870,"Current cut statistics: 2m, 0min, blade on time:
0min","#2E2EFE","bold"],
Working example (but not in JS) here: https://regex101.com/r/oL9gN5/11
Additional hints:
The meters are not always 6 chars long, may be 7 in a few years
Sometimes the string Total statistics:
occurs twice in the log, the first match(newer data) is needed.
For clarification:
in most cases I would have used JSON parsing(and you should use too), but the rest of the log is mostly useless data and I need only this one data point. The mower creates a log entry every time it hits an obstacle or turns at the edge of the zone(I cut that part out). Also it shows only the last 100 lines of log with no option to go forward/back.
It took me a while to figure this regexp out, only to find it doesn't work in JS(iobroker), thx for any help!
Upvotes: 1
Views: 2045
Reputation: 18357
You can use this regex and capture your data from group1,
Total statistics:\s+(\d+)
Here, it will match the first occurrence of Total statistics:
followed by one or more spaces and then (\d+)
will capture the numbers in first grouping pattern.
Upvotes: 1