Thanks @ghukahr and @picklu for attempting this regex. I think I need to further explain what first1 and first2 are. I did not really mean for the 1 and 2 to be digits per say.
The words before the second / can be red, blue, or green and the words after /middle/ can be one, two, three, four, or five.
The word middle needs to be middle. See below for a better example of what I am trying to achieve
const regex = ???
const path1 = '/red/middle/twoiabc/xyz';
const matches1 = regex.exec(path1);
console.log(matches) // should return [ 'red', 'two' ]
const path2 = '/blue/middle/three/mnso/jgsl';
const matches2 = regex.exec(path2);
console.log(matches2) // should return [ 'blue', 'three' ]
Also, there is one additional requirement I did not mention the first time which I should have. If the word before the second / is ‘yellow’, then I need to capture only the array [ ‘yellow’ ] like in the below path:
const path3 = '/yellow/blah/mnso/jgsl';
const matches3 = regex.exec(path3);
console.log(matches3) // should return [ 'yellow' ]