Regular expressions examples

When you are developing scripts, there will be many instances where you may want to use regular expressions. This section will explore regular expressions that you may run into in your environment. Since there are many methods to creating regular expressions, these are to be used as suggested starting points for your scripts.

The following diagram shows how to evaluate a MAC Address:

Regular expressions examples

To test a MAC address against a regular expression, use this syntax:

"00:a0:f8:12:34:56" -match "^([0-9a-f]{2}:){5}[0-9a-f]{2}$"

The output of this is shown in the following screenshot:

The preceding example shows how to create a regular expression ...

Get Mastering Windows PowerShell Scripting now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.