function resolve(path) { const match = /^\/api\/(v1|v2)\//.exec(path); return match ? match[1] : "unsupported"; } console.log(resolve("/api/v2/orders")); console.log(resolve("/api/v3/orders"));