小编Sum*_*and的帖子

使用正则表达式提取匹配项,然后将它们传递给数组

 $htmltitle1 = "{Quit|Discontinue|Stop|Cease|Give Up} Tottenham Manager {HEY}"
  $reg = "\{.*?\}"
  $found = $htmltitle1 -match $reg

  $spuntext = @()
  If ($found)
    {    
         ([regex]$reg).matches($htmltitle1)  
    }
Run Code Online (Sandbox Code Playgroud)

我可以看到$ 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
Run Code Online (Sandbox Code Playgroud)

powershell

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

powershell ×1