Chapter 13. Regular expressions
This chapter covers
- Regular expression syntax
- The –match operator
- Regular expressions in select-string
- Regular expressions in the switch statement
- The REGEX object
Regular expressions are a powerful and complex language you can use to describe data patterns. Most pattern-based data, including email addresses, phone numbers, IP addresses, and more, can be represented as a “regex,” as they’re also known.
We need to set some limits for this chapter, because regular expressions are complex enough to deserve their own book. PowerShell uses industry-standard regex syntax and supports the full .NET regular expression library, but we’ll only be covering the basics. Most of our focus will be on how PowerShell uses a regex once you’ve written one. If you’d like to explore regular expressions further, write more complex expressions, or look for a regex that meets a particular need, we recommend one of these two books as a starting place: Mastering Regular Expressions by Jeffrey E.F. Friedl (a favorite), and Regular Expression Pocket Reference by Tony Stubblebine, both from O’Reilly. You can also visit http://RegExLib.com, a free community repository of regular expressions for specific tasks.