常用到的有三种:
1、 -match 运算符,通过 $Matches来获取字段。
比如我之前的或取ip地址:http://hi.baidu.com/shrekzz/item/1bcf45ffc04d461fff3582fc
$WebClient=new-object System.Net.WebClient
$url="http://iframe.ip138.com/ic.asp"
$WebClient.DownloadString($url) -match '(?<ip>(\d+\.){3}\d+)'|out-null
$Matches.ip
日志入库中的方法:http://hi.baidu.com/shrekzz/item/4add3720c11b790143634a21
$cname|%{$_ -match 'ERROR...(?<time>.+):\d+ 区ID = (?<zoon>\d+) , 组ID = (?<group>\d+) , 线ID = (?<line>\d+) , 人数 = (?<num>\d+)'
$logtime=$Matches.time
$logtype=1902
$regionid=$Matches.zoon
$groupid=$Matches.group
$lineid=$Matches.line
$online_role_count=$Matches.num
}
2、matches()方法获取字段。
$txt='aaaa ssd <112@baidu.com>;
bbs sdg wwe <22888@baidu.com>;
333p998 44iiiiiiii<aab@baidu.com>;
33 341 <44@baidu.com>;'
[regex]::matches($txt, '<(.+)>;') | %{$_.Groups[1].Value}
3、-split方法
("we-rt-192.168.12.11-45.exe" -split "-")[2]