JS正则表达式路径名匹配

JS regex pathname match

我对正则表达式有点迷茫。我想要创建的是一个简单的检查和匹配路径。 (正则表达式菜鸟)

澄清;

应用程序可以有子目录

/
/dashboard/modules
/modules/acounting/
/modules/acounting/stats
/modules/invoicing/
/modules/invoicing/invoices

我想要完成的是匹配从第一个正斜杠到除了页面之外的所有斜杠。

/
/dashboard/
/modules/acounting/
/modules/invoicing/

尝试过//([^/]+)/[^/]*$/)

const url = window.location;
url.pathname.match(/\/([^/]+)\/[^/]*$/)

它创建一个数组。正则表达式帮助表示赞赏

您可以简单地使用 .*\/

Regex101 example and description

如果你想要 filter-match 个部分(相对于页面),请使用:.*\/$

Regex101 example and description