我有一个函数tabLength,应该返回一个字符串.这是为了在文本文档中进行格式化.
任何人都可以检查我的switch语句,看看为什么我在第6行收到错误.这就是switch语句正在经历的"情况".
Function tabLength ( $line ) {
$lineLength = $line.Length
switch -regex ( $lineLength ) {
"[1-4]" { return "`t`t`t" }
"[5-15]" { return "`t`t" }
"[16-24]" { return "`t" }
default { return "`t" }
}
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
Invalid regular expression pattern: [5-15].
At C:\Users\name\desktop\nslookup.ps1:52 char:11
+ "[5-15]" <<<< { return "" }
+ CategoryInfo : InvalidOperation: ([5-15]:String) [], RuntimeException
+ FullyQualifiedErrorId : InvalidRegularExpression
Run Code Online (Sandbox Code Playgroud)
它只发生在发送的价值观上[5-15].