For example '/mentor/33 is url'
I do this with regex: buildRegex('/mentor/:id');
'/mentor/:id' becomes '/mentor/[^/]'
const PATH_PARAM = {
PREFIX: ':',
REGEX_IDENTIFIER: '/:[^/]+',
REGEX_REPLACER: '/[^/]+',
};
private buildRegex(path: string) {
return this.ensureLeadingSlash(path).replace(
new RegExp(PATH_PARAM.REGEX_IDENTIFIER, 'g'),
PATH_PARAM.REGEX_REPLACER
);
}
How can I just to get back 33, so value from [^/]?
If I use this
private matchRegex(routeLink: string, routeRegex: string) {
const match = routeLink.match(new RegExp(routeRegex, "g"));
return match?.[0];
}
then I get back /mentor/33 and not 33. I am looking for generic approach.