git 提交主题中字符串的 Powershell 正则表达式

问题描述 投票:0回答:1

我正在尝试使用此 git log

"Version_10.1.18.1...Version_10.1.18" --format="
%s”来执行 git log,仅针对像这样的提交消息中的`主题

Merged PR 17055: 94683: Add back in Treat Warnings as Errors
Merged PR 17054: #94658: Add OwnerInfo to address data when multiple locations returned by LPS.

蒂亚

我正在使用以下正则表达式来删除冒号和文本合并 PR

     $regex = '[:]|(Merged PR)' # Regex to match commit hashes   
     $log= $gitHist -replace $regex, ""

所以看起来像这样

17055 94683 Add back in Treat Warnings as Errors
17054 #94658 Add OwnerInfo to address data when multiple locations returned by LPS.

接下来,我想仅获取工作项编号,即 94658 等,并将其放入变量中。这可以通过 powershell 中的正则表达式实现吗?

regex git powershell
1个回答
0
投票

您可以使正则表达式更具体一些,然后首先检查是否存在匹配项。如果存在,请将捕获组 1 中的值分配给变量。

查看此 正则表达式演示中的正则表达式匹配

if ($gitHist -match '\bMerged\s+PR\s+\d+:\s*#(\d+):') {
    $workItemNumber = $matches[1]
}
© www.soinside.com 2019 - 2024. All rights reserved.