← All Exercises

Regex Named Groups

basicpython~15min

Background

Named regex groups make pattern matching results more readable and maintainable.

Problem

Parse a log line using regex named groups to extract timestamp, level, and message fields.

Input

A log line string

Output

Dictionary of named captures

Sample tests

Sample 1

Input: "2024-01-01 ERROR Something failed"
Expected: {date, level, msg}

Your solution

Learning objective

Learn regex patterns and named capture groups