O'Reilly logo

Windows PowerShell Cookbook, 3rd Edition by Lee Holmes

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix B. Regular Expression Reference

Regular expressions play an important role in most text parsing and text matching tasks. They form an important underpinning of the -split and -match operators, the switch statement, the Select-String cmdlet, and more. Tables B-1 through B-9 list commonly used regular expressions.

Table B-1. 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.

PS > "T" -match '.'
True

[characters]

Any character in the brackets. For example: [aeiou].

PS > "Test" -match '[Tes]'
True

[^characters]

Any character not in the brackets. For example: [^aeiou].

PS > "Test" -match '[^Tes]'
False

[start-end]

Any character between the characters start and end, inclusive. You may include multiple character ranges between the brackets. For example, [a-eh-j].

PS > "Test" -match '[e-t]'
True

[^start-end]

Any character not between any of the character ranges start through end, inclusive. You may include multiple character ranges between the brackets. For example, [^a-eh-j].

PS > "Test" -match '[^e-t]'
False

\p{character class}

Any character in the Unicode group or block range specified by {character class}.

PS > "+" -match '\p{Sm}'
True

\P{character class}

Any character not in the Unicode group or block range specified by {character class}.

PS > "+" -match '\P{Sm}'
False

\w

Any word character. Note that this is the Unicode definition ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required