我使用下面的正则表达式代码捕获两个匹配的组:
[regex]$regex = "^([0-9]{1,20})(b|kb|mb|gb|tb)$"
$matches = $regex.match($minSize)
$size=[int64]$matches.Groups[1].Value
$unit=$matches.Groups[2].Value
我的问题是我想使其不区分大小写,并且我不想使用正则表达式修饰符。
我知道您可以在 .NET 中传递正则表达式选项,但我不知道如何使用 PowerShell 执行相同的操作。
静态有过载[Regex]::Match()允许提供所需的方法[RegexOptions]
以编程方式:
# You can combine several options by doing a bitwise or:
$options = [Text.RegularExpressions.RegexOptions]::IgnoreCase -bor [Text.RegularExpressions.RegexOptions]::CultureInvariant
# or by letting casting do the magic:
$options = [Text.RegularExpressions.RegexOptions]'IgnoreCase, CultureInvariant'
$match = [regex]::Match($input, $regex, $options)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)