liveBook · Manning

Chapter 21: Using regular expressions to parse text files

What you will learn in chapter 21 of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

The introduction positions regular expressions as an occasional PowerShell tool for parsing text files, such as logs.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction positions regular expressions as an occasional PowerShell tool for parsing text files, such as logs.

Key terms: regular expressions, regex, text parsing, log file

21.1 The purpose of regular expressions

This section explains that regular expressions define text patterns for finding and extracting text, but do not necessarily validate the data they match.

Key terms: regular expression, text pattern, validity, detect, capture, matched text, log file

21.2 A regex syntax primer

Introduces basic regular-expression syntax in PowerShell and shows how to combine patterns while recognizing matches that are broader than intended.

Key terms: regex, case insensitive, \w, \d, \s, ., [abcde], [^abcde], ?, *

21.3 Using regex with -Match

This section shows how to test a regular expression against a string with PowerShell’s -Match operator.

Key terms: -Match, -CMatch, left-hand operand, right-hand operand, regular expression

21.4 Using regex with Select-String

Shows how to use Select-String and regular expressions to find relevant text in web server logs and Windows Security event messages, while choosing what the command outputs.

Key terms: 40x errors, \s40[0-9]\s, space-delimited fields, *.log, Select-String, MatchInfo, Format-Table, user-agent strings, WOW64, 10\.0;[\w\W]+\+Gecko

21.5 Lab

21.6 Lab answers

21.7 Further exploration

This section points out additional places PowerShell uses regular expressions and identifies resources for finding and testing patterns.

Key terms: Switch, regular expression–based input-validation tool, -Match, $matches, industry-standard regex syntax, RegExLib.com, RegExTester.com

Where this is used later

Concepts explained in this chapter

← Chapter 20: Improving your parameterized script Chapter 22: Using someone else’s script →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.