标签: javascript regex
我正在尝试使用JavaScript中的正则表达式来匹配页面位置。基本上,我想检查字符串是否为/dashboard +任何字符,例如/dashboard,/dashboard/activity/,/dashboard/myaccount ...
/dashboard
/dashboard/activity/
/dashboard/myaccount
我尝试使用.*:/dashboard${/.*/}来做到这一点,但是没有运气。
.*
/dashboard${/.*/}
我应该怎么做?
预先感谢
答案 0 :(得分:0)
const regex = /\/dashboard(\/\w+)*/; const test = "/dashboard/hello".match(regex) const testA = "/dashboard/hello/world".match(regex) const testB = "/dashboard".match(regex) const testC = "/hello/world".match(regex) console.log(test); console.log(testA); console.log(testB); console.log(testC);