Chapter 5. Regular Expressions

When you are scripting, you will run into situations where you need to validate strings to see if they meet certain criteria. While you have the ability to use comparison operators to view if a string matches a certain value, you don't have the ability to validate parts of a string. A good example is of IP addresses. The comparison operators don't have the ability to validate the syntax of an IP address. If you were to use the normal comparison operators to validate an IP address syntax, you would have to build a script that would split the numerical values, verify that it has 4 octets, validate the individual numerical values, and pass a True or False value. Regular expressions solve this problem by providing deep ...

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.