吐槽 : 中国境内搜Powershell的用法真的少得可怜,不得已开通vpn
Powershell 基于.net集成,亦都沿用了.net语法,跟Python有点不一样
正则语法非常简单,直接上代码:
例如pattern 为 '[\u4e00-\u9fa5]' , 匹配中文字符
$sMatch_Content = "12sdw这@F@#年H头^&*^%^猪都V#sad会2b45b5*(上h45y45树3TNYT%ver";
$ret = [regex]::Matches($sMatch_Content,'[\u4e00-\u9fa5]');
foreach ($item in $ret){
write-host $item.Value;
}
[String]::Join('', ($ret | Select-Object -ExpandProperty Value))
$ret -join '';
结果:
[String]::Join('', ($ret | Select-Object -ExpandProperty Value)) 和 $ret -join '';都是用于合并字符串