'Combining Regex Patterns from various Urls
I have the following urls and I am trying to combine them into one pattern rather than multiple. How should I write this? The conditional I'm writing needs to test if it matches users or cases or both or all three, etc..
const casesUrl = /\/api\/v1\/cases\/[\w-]+/g
const usersUrl = /\/api\/v1\/users\/[\w-]+/g
const lawfirmsUrl = /\/api\/v1\/lawfirms\/[\w-]+/g
Is there a better way to do this than writing multiple conditional statements like below?
if (usersUrl.test(response.config.url) ) {
return $q.reject(response);
}
I have tried doing something similar here with no luck:
const regexUrl = /\/api\/v1\/(users|cases)\/[\w-]+/g
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
