【发布时间】:2022-12-02 21:25:30
【问题描述】:
我不明白正则表达式:( 我想查找路径是否仅包含 7 位数字 例如:
C:\Users\3D Objects\1403036 --> the result should be 1403036
C:\Users\358712\1403036 --> the result should be 1403036
等等
我努力了:
$FilesPath -match '([\d{1,7}]{7})')
和
$FilesPath -match '(\d{7})')
目前我正在处理:
$FilesPath = Read-Host -Prompt
if ($Matches[1].Length -eq '7') {
$FolderNumber = $Matches[1]
}
这是不对的,因为如果路径中包含数字 3 则不匹配
如果是这种情况:
C:\Users\3D Objects\1403036854 --> More than 7 digits the result should be empty
或者
C:\Users\3874113353D Objects\1403036 --> Should return result for 1403036
我没有数组,只是想知道是否有一个数字正好是 7 位数字,如果包含少于或多于 7 位数字则没有
【问题讨论】:
标签: powershell