Book Image

Mastering Windows PowerShell Scripting

By : Brenton J.W. Blawat
Book Image

Mastering Windows PowerShell Scripting

By: Brenton J.W. Blawat

Overview of this book

Table of Contents (22 chapters)
Mastering Windows PowerShell Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting started with regular expressions


In the most basic form, regular expressions are used to match a specific set of characters contained in a string. To use regular expressions in PowerShell, you need to leverage the –match, –notmatch, and –replace operators in conjunction with an expression. The proper syntax for the comparison operators is referencing a variable or string, followed by the –match, –notmatch, or –replace operator and then the expression you want to evaluate. If the comparison operator is –match or –notmatch, the expression will return either True or False. If you use the –replace operator, the expression will return the string or variable with the replaced values.

Tip

By default, PowerShell's –match operator is case-insensitive. This means it will return $True if the letter exists. To fully leverage the regular expression's case sensitivity, use –cmatch. The –cmatch operator is for case match and will make the matching case-sensitive.

Regular expressions have characters...