Powershell Regular Expression Cheat Sheet

Posted : admin On 1/29/2022

To match larger numbers requires a more complex regex, to test the numbers 0 to 19 test a match with 0-9 OR ( ) the number 1 followed by 0-9: PS C: 12 -match '^(0-9 10-9)$' True. To test the numbers 0 to 99: PS C: 45 -match '^(0-9 0-90-9)$' True. Will match a single character: PS C: 'cat' -match 'c.t' True. Windows PowerShell Commands Cheat Sheet We break down what Windows PowerShell is, and provide you a definitive downloadable PowerShell Commands Cheat Sheet (PDF) as a quick reference to get you started and running your own commands. Tim Keary Network administration expert UPDATED: March 31, 2021. 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.

Say you want to find functions that uses parameters named like:
-AsString, -AsHashTable, or-AsByteStream
Using Find-Member makes it easy.

That’s close, but I want it to start with a capital letter, to skip matches like:
Assembly or Asin

Converting Like to a Regex

The -like pattern As* is the same as the regex ^As
To start with a capital letter you could use: ^As[A-Z]

Disabling Case-Sensitive matches

Because PowerShell defaults to case-insensitive matches
You need to remove the iinsensitive flag using the syntax (?-i)

Solution

The final pattern is (?-i)^As[A-Z]
Making it case-sensitive narrowed down the matches from 113 to 43 !

Powershell Regular Expression Cheat Sheet Answers

See More

CheatPowershell Regular Expression Cheat Sheet

Powershell Regular Expression Cheat Sheet Pdf

  • get Find-Member from ClassExplorer