Recap - Log File Parser
Part of the Logic & Flow section of Coddy's Lua journey — lesson 40 of 54.
Challenge
EasyWrite a function parseLogEntry that takes logEntry and returns the extracted log information in a formatted string.
Use string.match() with multiple captures to extract the log level (in brackets), the message text, and the numeric ID from the log entry. Return these three pieces of information separated by commas.
Logic:
- Use a pattern with three captures: one for the log level inside brackets, one for the message text, and one for the numeric ID
- The log level is uppercase letters inside square brackets
- The message is text between the colon and the numeric ID
- The ID is one or more digits at the end
- Return the three captured values in the format:
level,message,id
Parameters:
logEntry(string): A log entry in the format[LEVEL]: Message text ID
Returns: The extracted information as level,message,id (string)
Try it yourself
function parseLogEntry(logEntry)
-- Write code here
end
All lessons in Logic & Flow
1Advanced Table Iteration
Iterating with pairs()Iterating with ipairs()pairs() vs. ipairs()Recap - Character Sheet4Introduction to Metatables
What is a Metatable?setmetatable & getmetatableThe __index MetamethodThe __newindex MetamethodThe __tostring MetamethodArithmetic Metamethods Part 1Arithmetic Metamethods Part 2Recap - Read-Only Table7Advanced String Manipulation
string.gsub() for SubstitutionIntro to String Patternsstring.find()string.match()Iterating with string.gmatch()Recap - Log File Parser2More Table Library Functions
table.concat()table construction & unpack()table.sort()Custom Sorting with FunctionsRecap - High Score Board