Is it possible to parse both of these urls with a single regex?
First is in this format for a path under project:
const str1 = "https://gitlab.com/myproject/my_product/prd/projectbranch/-/tree/master/src/tools/somepath/somename"
Second is in this format for an MR:
const str2 = "https://gitlab.com/myproject/my_product/prd/projectbranch/-/merge_requests/20"
Im able to parse the first like this:
const [_, baseUrl, type, branchName, relativePath] = str1.match(/(.*)\/-\/(tree|merge_requests)\/(.+?)(?:\/(.*$))/)
But I couldnt manage to parse the first and second strings in a single regular expression.
Basically I want to do sth like this (This doesnt work):
const [_, baseUrl, type, mergeRequestNumber] = str2.match(/(.*)\/-\/(tree|merge_requests)\/(.+?)(?:\/(.*$))/)
Edit: I want mergeRequestNumber
to match 20
in 2nd match without breaking the 1st match.