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...