The wildcard and regex parameters are used when matching strings. The wildcard parameter allows 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 the use of regular expressions to perform comparisons (Chapter 10, 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' } }