I have the below input from a Git log:
Merge: d9335ae 7d12d50
Author: name\name <[email protected]>
Date: Wed Oct 31 12:55:00 2018 -0500
id:202847 Merge branch 'release/2.6.0' into release/3.0.0
# Conflicts:
# configuration/path/path
I need to parse the id:xxxxx
and then pass that id into the target process API which returns the ID name.
I have a custom PowerShell function that accomplishes this.
What I need help with is combining this into one PowerShell function that does this. My regular expression to match the id is a simple id:\d+
.
My desired outcome is the output to look like the below (the text after the ID is what's returned from the target process):
TP Id:202847 Professional Lines: 2,800,000 Policy Aggregate Limit update
PowerShell has very powerful native regular expression support, and you can pretty easily retrieve the ID value from your Git commands like so. We begin by capturing the output of your git command (in my case, I pasted it into a variable, but you could also run
$CommitMsg = git commit 202847
to capture the output into a variable another way :)Next, I use the PowerShell regular expression accelerator (
[regex]
, PowerShell has lots of useful accelerators!) to look through the variable$r
for matches for the regular expression patternid:.....\w+
, which looks for a string that starts withid:
and has six characters after it, then a white space.You can store that output in a variable like so:
and then embed that into your other command using string expansion, like this: