Q:

How to extract value from the string in bash?

I have an input string in the following format: 
bugfix/ABC-12345-1-00

I want to extract "ABC-12345". Regex for that format in C# looks like this: 
.\*\\/([A-Z]+-[0-9]+).\*

How can I do that in a bash script? I've tried sed and awk but had no success because I need to extract value from the capturing group and skip the rest.

A:

If your grep supports -P then you could use the below grep commands.
$ echo 'bugfix/ABC-12345-1-00' | grep -oP '/\K[A-Z]+-\d+'
ABC-12345

\K  keeps the text matched so far out of the overall regex match.
$ echo 'bugfix/ABC-12345-1-00' | grep -oP '(?<=/)[A-Z]+-\d+'
ABC-12345

(?<=/) Positive lookbehind which asserts that the match must be preceded by a / symbol.
Through sed,
$ echo 'bugfix/ABC-12345-1-00' | sed 's~.*/\([A-Z]\+-[0-9]\+\).*~\1~'
ABC-12345

