Level 3: Advanced · Lesson 30 of 30
Capstone: Parse a Log File
Bring everything together by pulling dates, levels, messages, emails and addresses out of a realistic log. Each task combines several techniques from earlier lessons.
This final lesson combines the tools you have learned into one realistic job: making sense of a log file. Logs are a perfect regex playground because they mix fixed structure, such as dates and level names, with free text, such as error messages, user emails and network addresses.
Start with structure. A typical line looks like 2026-11-30 ERROR Disk full. Named groups make the pieces obvious: (?<date>\d{4}-\d{2}-\d{2}) (?<level>INFO|WARN|ERROR) (?<msg>.+). The alternation lists the allowed levels, and .+ takes the rest of the line. Because . does not match a newline unless you use the s flag, each match stops at the end of its line.
Next, filter. Suppose you only care about errors. With the m flag, ^ marks the start of each line, so the lookbehind (?<=^ERROR ).+ returns just the message text from lines that begin with ERROR. In Go or Rust, which lack lookbehind, write ^ERROR (.+) and read group 1.
Then extract values buried in the text. Emails use a practical pattern such as [\w.]+@[\w-]+(?:\.[\w-]+)+, which requires at least one dot in the domain. Remember that this is a practical subset, not a complete implementation of the email standard. Dotted addresses like 10.0.0.1 fit \b\d{1,3}(?:\.\d{1,3}){3}\b, which checks shape only; it would also accept 999.999.999.999.
When you need real validation, tighten the ranges. A date with a sensible month and day uses alternation: (?:0[1-9]|1[0-2]) for months and (?:0[1-9]|[12]\d|3[01]) for days. It still cannot tell that 31 February does not exist; that check belongs in code.
Keep performance in mind. Log files can be large, so avoid nested quantifiers and prefer negated classes like [^\]]+ over lazy wildcards when a single delimiter marks the end. If a pattern ever trips RegexLab's 500 ms timeout on sample data, it will be far worse on a production log.
Finally, think about where the pattern will run. If your log processor is written in Python, rename groups with (?P<name>...). If it is in Go, replace lookarounds with captures. Use the generator, the explainer and the converter together, and you have a workflow that takes you from an idea to a tested, portable pattern.
Live tester
2 matches (JavaScript engine)
2026-11-30 ERROR Disk full 2026-11-30 INFO Service started malformed line
Examples
Numbers
/\b\d{1,3}(?:\.\d{1,3}){3}\b/Requests from 10.0.0.1 and 192.168.0.10 were logged.
Matches: “10.0.0.1”, “192.168.0.10”
Four dotted number groups describe the address shape; the values are not range-checked.
Text
/(?<=\[)[^\]]+(?=\])/[auth] login ok [db] slow query
Matches: “auth”, “db”
Lookbehind and lookahead strip the brackets, leaving only the component names.
Codes
/\b[A-Z]{2,5}-\d+\b/Fixed CORE-12 and UI-7 in this release.
Matches: “CORE-12”, “UI-7”
Ticket references in log messages follow a letters-dash-number shape.
Practice tasks
Your regex runs over the text with the global flag. It passes when it finds every required match and nothing that should be left out.
Task 1: Extract only the message text from lines that start with `ERROR `.
INFO start ERROR disk full WARN low memory ERROR timeout
Task 2: Extract the email addresses from the log line, but not the network address.
user=ali@example.com ip=10.0.0.1 user=sara@demo.test
Task 3: Validate one ISO date per line with a month from 01 to 12 and a day from 01 to 31.
2026-01-31 2026-13-01 2026-12-05