$htmltitle1 = "{Quit|Discontinue|Stop|Cease|Give Up} Tottenham Manager {HEY}"
$reg = "\{.*?\}"
$found = $htmltitle1 -match $reg
$spuntext = @()
If ($found)
{
([regex]$reg).matches($htmltitle1)
}
我可以看到$matches (如下所示),但是如何将每个匹配项提取到$spuntext数组中?哈哈,我已经花了几个小时尝试不同的东西了。
Groups : {{Quit|Discontinue|Stop|Cease|Give Up}}
Success : True
Captures : {{Quit|Discontinue|Stop|Cease|Give Up}}
Index : 0
Length : 37
Value : {Quit|Discontinue|Stop|Cease|Give Up}
Groups : {{HEY}}
Success : True
Captures : {{HEY}}
Index : 56
Length : 5
Value : {HEY}
Key : 0
Value : {Quit|Discontinue|Stop|Cease|Give Up}
Name : 0
发布于 2013-06-29 04:46:21
我今天在尝试学习语法后也想出了这个,以防它对任何像我一样困惑的新手有帮助:(在v2中工作)
$htmltitle1 = "{Quit|Discontinue|Stop|Cease|Give Up} Tottenham Manager {HEY}"
$reg = "{.*?}"
$found = $htmltitle1 -match $reg
$spuntext = @()
If ($found)
{
[regex]::matches($htmltitle1, $reg) | % {$spuntext += $_.Value}
}
$spuntext
https://stackoverflow.com/questions/17353326
复制相似问题