简体   繁体   中英

Match Regular Expression in string

I'm trying to match a page location using regular expressions in JavaScript. Basically, I want to check if the string is /dashboard + any character, eg, /dashboard , /dashboard/activity/ , /dashboard/myaccount ...

I tried to do it using .* : /dashboard${/.*/} but got no luck.

How should I do it?

Thanks in advance

在此处输入图片说明

 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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM