The following appendices provide a core reference for some of the detailed areas of PowerShell – and of the broad technologies that PowerShell lets you interact with.
Regular expressions play an important role in most text parsing and text matching tasks. They form an important underpinning of the –match operator, the switch statement, the Select-String cmdlet, and more.
Character Classes | |
---|---|
Patterns that represent sets of characters | |
Character Class | Matches |
| Any character except for a newline. If the regular expression uses the SingleLine option, it matches any character. |
| Any character in the brackets. For example: |
| Any character not in the brackets. For example: |
| Any character between the characters
start and end, inclusive. You may include multiple character
ranges between the brackets. For example, |
| Any character not between any of the
character ranges start through end, inclusive. You may include
multiple character ranges between the brackets. For example,
|
| Any character in the Unicode group or block range specified by {character class}. |
| Any character not in the Unicode group or block range specified by {character class}. |
| Any word character. |
| Any non-word character. |
| Any whitespace character. |
| Any non-whitespace character. |
| Any decimal digit. |
| Any non-decimal digit. |
Quantifiers | |
---|---|
Expressions that enforce quantity on the preceding expression | |
Quantifier | Meaning |
| One match. |
| Zero or matches, matching as much as possible. |
| One or more matches, matching as much as possible. |
| Zero or one matches, matching as much as possible. |
| Exactly n matches. |
| n or more matches, matching as much as possible. |
| Between n and m matches (inclusive), matching as much as possible. |
| Zero or one matches, matching as little as possible. |
| One or more matches, matching as little as possible. |
| Zero or one matches, matching as little as possible. |
| Exactly n matches. |
| n or more matches, matching as little as possible. |
| Between n and m matches (inclusive), matching as little as possible. |
Grouping Constructs | |
---|---|
Expressions that allow you to group characters, patterns, and other expressions | |
Grouping Construct | Description |
| Captures the text matched inside of the parentheses. These captures are named by number (starting at one) based on the order of the opening parenthesis. |
| Captures the text matched inside of
the parentheses. These captures are named by the name given in
|
| A balancing group definition. This is an advanced regular expression construct, but allows you to match evenly balanced pairs of terms. |
| Non-capturing group. |
| Applies or disables the given option for this group. Supported options are: |
| Zero-width positive lookahead assertion. Ensures that the given pattern matches to the right, without actually performing the match. |
| Zero-width negative lookahead assertion. Ensures that the given pattern does not match to the right, without actually performing the match. |
| Zero-width positive lookbehind assertion. Ensures that the given pattern matches to the left, without actually performing the match. |
| Zero-width negative lookbehind assertion. Ensures that the given pattern does not match to the left, without actually performing the match. |
| Non-backtracking subexpression. Matches only if this subexpression can be matched completely. The non-backtracking version of the subexpression fails to match, as its complete match would be “Hello World”. |
Atomic Zero-Width Assertions | |
---|---|
Patterns that restrict where a match may occur | |
Assertion | Restriction |
| The match must occur at the
beginning of the string (or line, if the |
| The match must occur at the end of
the string (or line, if the |
| The match must occur at the beginning of the string. |
The match must occur at the end of
the string, or before | |
| The match must occur at the end of the string. |
| The match must occur where the
previous match ended. Used with the |
The match must occur on a word boundary—the first or last characters in words separated by nonalphanumeric characters. | |
| The match must not occur on a word boundary. |
Substitution Patterns | |
---|---|
Patterns used in a regular expression replace operation | |
Pattern | Substitution |
| The text matched by group number
|
| The text matched by group named
|
| A literal |
| A copy of the entire match. |
| The text of the input string that precedes the match. |
| The text of the input string that follows the match. |
| The last group captured. |
| The entire input string. |
Alternation Constructs | |
---|---|
Expressions that allow you to perform either/or logic | |
Alternation Construct | Description |
| | Matches any of the terms separated by the vertical bar character. |
| Matches the |
| Matches the |
Backreference Constructs | |
---|---|
Expressions that refer to a capture group within the expression | |
Backreference Construct | Refers To |
| Group number |
| The group named |
Other Constructs | |
---|---|
Other expressions that modify a regular expression | |
Construct | Description |
| Applies or disables the given option for the rest of this expression. Supported options are: |
| Inline comment. This terminates at the first closing parenthesis. |
Comment form allowed when the
regular expression has the |
Character Escapes | |
---|---|
Character sequences that represent another character | |
Escaped Character | Match |
| Characters other than |
| A bell (alarm) |
A backspace | |
| A tab |
| A carriage return |
| A vertical tab |
| A form feed |
| A new line |
| An escape |
| An ASCII character as octal (up to three digits.) Numbers with no leading zero are treated as backreferences if they have only one digit, or if they correspond to a capturing group number. |
| An ASCII character using hexadecimal representation (exactly two digits). |
| An ASCII control character; for
example, |
| A Unicode character using hexadecimal representation (exactly four digits). |
When followed by a character that is
not recognized as an escaped character, matches that
character. For example, |
3.142.135.4