吐槽 : 中国境内搜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 '';都是用于合并字符串
本文介绍如何在Powershell中使用正则表达式来匹配中文字符,并提供了具体的代码实例。通过示例展示了如何提取特定字符并进行字符串合并。
3636

被折叠的 条评论
为什么被折叠?



