Check if a string starts with a possible range of values and extract the match

Viewed 67

Given the following JavaScript code:

const branch = 'PRODUCT-1234-foobar';
const match = (/^(?:product|core|shop)-\d+/i).exec(branch);
const name = match ? match[0] : 'unknown';

Given a branch that starts with either PRODUCT-, CORE- or SHOP- and is followed by at least one number, this will give me the first part of the name of the branch, in this case PRODUCT-1234.

I've been trying to do the same in Bash, but I cannot seem to make it work. How would I do this? The answer should preferably be case-insensitive.

1 Answers
Related