There is a string "Paul Cervov <paul.cervov@example.com>".
I want to get just username from email address.
In bash we can do so:
COMMIT_AUTHOR_NAME=$(echo "$CI_COMMIT_AUTHOR" | sed "s/.*\<\(.*\)\@.*/\1/g")
How can I do same with PowerShell?
>Solution :
You can use PowerShell -replace regex operator:
"Paul Cervov <paul.cervov@example.com>" -replace '.*<(.*)@.*', '$1'
# or, with variables:
$COMMIT_AUTHOR_NAME = $CI_COMMIT_AUTHOR -replace '.*<(.*)@.*', '$1'
As you can see, the only real difference is that .NET’s regex engine uses $1 instead of \1 to refer to the 1st capture group in the substitution string.