Skip to content

Regular expressions for log searching with grep, Select-String and Python

For service desk, systems and security staff who search text logs and want answers they can trust and repeat. You should be comfortable at a Linux or PowerShell prompt; reading basic Python helps for one lesson, but you don't need to write programs. Covers the pattern syntax you need for log lines (character classes, quantifiers, anchors, word boundaries), the options that change results in GNU grep, PowerShell Select-String and Python's re module, extracting fields with capture groups, testing patterns so they neither over- nor under-match, avoiding patterns that hang on crafted input, and recording a search so someone else can repeat it. Only search logs you are authorised to read; your organisation's rules decide where log extracts may be kept. Ends with a supervisor-graded log search exercise.

Level
Intermediate
Length
About 95 minutes
Contents
5 lessons · final exam
Status
Published · updated 10 Oct 2026

Skills you'll practise

  • Write a regular expression that matches a log field using character classes, quantifiers, anchors and word boundaries
  • Choose grep, Select-String or Python re options that give the result you need, including case sensitivity, fixed strings, inverted matches and counts
  • Extract fields from log lines with capture groups and named groups, without greedy over-matching
  • Identify regular expressions that over-match, under-match or risk catastrophic backtracking, by testing them against sample lines
  • Record a log search in a ticket so another person can repeat it, without copying personal data unnecessarily

Course outline

  1. 1.Write a regular expression that matches a log fieldLesson · 16 min
  2. 2.Choose grep, Select-String and Python options that give the result you needLesson · 18 min
  3. 3.Extract fields from log lines with capture groupsLesson · 16 min
  4. 4.Test patterns against sample lines to catch over-matching, under-matching and catastrophic backtrackingLesson · 16 min
  5. 5.Record a log search in a ticket so another person can repeat itLesson · 10 min
  6. 6.Regular expressions for log searching with grep, Select-String and Python: knowledge checkKnowledge check · 14 questions
  7. 7.Regular expressions for log searching with grep, Select-String and Python: practical exerciseKnowledge check · 1 question
  8. 8.Final exam10 questions · passing it completes the course, so people who already know the material can test out

Sources it draws on

The lessons and questions are written from these references, so learners can go back to the original.

See it with your own jobs and topics

Tell us about your team and we'll walk you through setup, from choosing jobs to your first skills check.