Issue
I have the following pipeline step which run a Regex
- TICKET_NAME="$(echo $BRANCH_NAME | sed -E 's~^(.*/){0,1}((ABV|ASD|WSX)-[0-9]{2,6})-.*~\2~I')"
Basically, the $BRANCH_NAME
can be the following
fix/ABV-123-test-version
ABV-4233-test-another-thing
feature/-ASD-my-feature
What I would like is, to always retrieve the ticket number which is always starting with ABV|ASD|WSX
and always end after the number.
so ABS-123
or ASD-3423
the number can be any number but it will always be the same pattern.
my current regex works, but it also capute the prefix so fix/ABV-123
I would like only the ABV-123
Solution
Using sed
$ sed -En 's~([^/]*/)?([AW][BS][VDX]-[0-9]+).*~\2~p' input_file
ABV-123
ABV-4233
Answered By - HatLess Answer Checked By - Clifford M. (WPSolving Volunteer)