【发布时间】:2019-08-19 20:50:08
【问题描述】:
基本上,我需要每行匹配 1 个,但现在,我的正则表达式每行匹配 2 个。
https://regex101.com/r/KmgGwS/8
我的正则表达式正在寻找 2 个斜杠,它返回中间的字符串,但问题是我的路径有多个斜杠,我只需要将它与每行的第二个匹配项匹配
(?<=\\).*?(?=\\)
这是我的 PowerShell 代码:
if ( $_.PSPath -match ("(?<=::).*?(?=\\)")) {
$user = $matches.Values
}
例如:
Microsoft.PowerShell.Security\Certificate::CurrentUser\Root\CDD4EEAE6000AC7F40C3802C171E30148030C072 Microsoft.PowerShell.Security\Certificate::CurrentUser\Root\BE36A4562FB2EE05DBB3D32323ADF445084ED656我的代码所做的是得到
证书::CurrentUserRoot 证书::CurrentUserRoot但我真正需要的是获得第二场比赛的字符串 \ ___\,即:
根 根【问题讨论】:
标签: regex powershell syntax-highlighting