与以下模式匹配的Powershell RegEx模式是什么?
+31 123456789
0123456789
0123 456 789
0 123 456 789
我需要将其纳入:
If ($MobilePhone.ToString() -match '0(?<CountryCode>d)s+(?<Number>.........)')
{ "+31 $($Matches['CountryCode']) $($Matches['Number'])" }
Else
{ $MobilePhone.ToString() }
我认为这可能会对您有所帮助:
$regex = "^([+|0-9 ][ 0-9.]{1,12})$"
$number = "+31 123456789"
if($number -match $regex){
Write-Host "It matches" -ForegroundColor Green
}else{
Write-Host "Invalid number" -ForegroundColor Red
}
开始
"+31 123456789" -match '^+d{2}sd{9}$'
"0123456789" -match '^d{10}$'
"0123 456 789" -match '^d{4}(sd+){2}$'
"0 123 456 789" -match '^d(sd{3}){3}$'
与相关:在不更改AD属性的情况下修改PowerShell以国际格式显示电话号码?