使用正则表达式参数 switch 语句

-Regex 参数允许 switch 语句根据条件执行正则表达式匹配。

例:

switch -Regex ('Condition')
{ 
  'Con\D+ion'    {'One or more non-digits'}
  'Conditio*$'   {'Zero or more "o"'} 
  'C.ndition'    {'Any single char.'}  
  '^C\w+ition$'  {'Anchors and one or more word chars.'} 
  'Test'         {'No match'} 
}

输出:

One or more non-digits
Any single char.
Anchors and one or more word chars.