Asserts that a string matches a regular expression.
Assert-Match [-Haystack] <String> [-Regex] <String> [[-Message] <String>] [<CommonParameters>]
Uses PowerShell's -match
operator, e.g. $Haystack -match $Regex
.
Name | Type | Description | Required? | Pipeline Input | Default Value |
---|---|---|---|---|---|
Haystack | String | The string that should match the regular expression |
true | false | |
Regex | String | The regular expression to use when matching. |
true | false | |
Message | String | The message to show when the assertion fails. |
false | false |
Assert-Match 'Haystack' 'stack'
Demonstrates how to check that a string matches regular expression.
Assert-Match 'NONumbers!' '\d' 'Ack! No numbers doesn''t have any numbers.'
Demonstrates how to show a specific message if the assertion fails.