Skip to content

Commit

Permalink
improve regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Apr 2, 2020
1 parent b0d2a1c commit 7232360
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
* output: 39292992
*/
export function getDashboardIdFromUrl(url: string): string | undefined {
const [, match1, match2, match3] = url.match(
/dashboard\/(.*)\/|dashboard\/(.*)\?|dashboard\/(.*)$/
) ?? [
const [, dashboardId] = url.match(/dashboard\/(.*?)(\/|\?|$)/) ?? [
undefined, // full match
undefined, // group1 - dashboardId is before `/`
undefined, // group2 - dashboardId is before `?`
undefined, // group3 - dashboardID is in the end
undefined, // group with dashboardId
];
return match1 ?? match2 ?? match3 ?? undefined;
return dashboardId ?? undefined;
}

0 comments on commit 7232360

Please sign in to comment.