Assert-Match

Asserts that a string matches a regular expression.

Syntax

Assert-Match [-Haystack] <String> [-Regex] <String> [[-Message] <String>] [<CommonParameters>]

Description

Uses PowerShell's -match operator, e.g. $Haystack -match $Regex.

Parameters

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

EXAMPLE 1

Assert-Match 'Haystack' 'stack'

Demonstrates how to check that a string matches regular expression.

EXAMPLE 2

Assert-Match 'NONumbers!' '\d' 'Ack! No numbers doesn''t have any numbers.'

Demonstrates how to show a specific message if the assertion fails.