The wildcard and regex parameters are used when matching strings. The wildcard parameter allows for the use of the characters ? (any single character) and * (any character, repeated 0 or more times) in a condition, for example:
switch -Wildcard ('cat') {
'c*' { Write-Host 'The word begins with c' } '???' { Write-Host 'The word is 3 characters long' } '*t' { Write-Host 'The word ends with t' } }
The Regex parameter allows for the use of regular expressions to perform comparisons (Chapter 9, Regular Expressions, will explain this syntax in greater detail), for example:
switch -Regex ('cat') {
'^c' { Write-Host 'The word begins with c' } '[a-z]{3}' { Write-Host 'The word is 3 characters long' } 't$' { Write-Host 'The word ends with t' } }