我有以下代码:
$dnisList = @"
jimenex joe, maria . 73337789N
jerse joan juana usuaria 73637089N.
"@
$dnisList.Trim().Split("`n") | where-object {
$a = $_ | select-string -pattern '^(\d{8})([A-Z])$'
write-host $a
}
输出:
juan mar yoy . 73337789N
juena juose jua, usuaria 73637089N.
我如何清理文档以仅保留数字?
预期输出:
73337789N
73637089N
答案1
您可以尝试这样做:
$dnisList = @"
juan mar yoy . 73337789N
juena juose jua, usuaria 73637089N.
"@
$pattern = "(\d{8})([A-Z])"
$results = $dnisList | Select-String $pattern -AllMatches | ForEach-Object {$_.Matches.Value}
$results
你将获得如下输出:
73337789N
73637089N