< Back

Assert-Match

Sun Jan 12, 2020 5:45 pm

NAME Assert-Match



SYNOPSIS

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

-Haystack <String>

The string that should match the regular expression



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Regex <String>

The regular expression to use when matching.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Message <String>

The message to show when the assertion fails.



Required? false

Position? 3

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Assert-Match 'Haystack' 'stack'



Demonstrates how to check that a string matches regular expression.









-------------------------- EXAMPLE 2 --------------------------



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



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











RELATED LINKS