Javascript 匹配特定的url模式
我有以下模式检查:Javascript 匹配特定的url模式,javascript,regex,ecmascript-6,Javascript,Regex,Ecmascript 6,我有以下模式检查: const myPattern = /^\/(abc|def|gh|how-to\/articles|xyz){1}/I; 上述内容与www.test.com/how-to/articles&www.test.com/how-to/articles/ 如何调整上面的模式,使其匹配 www.test.com/how-to/articles/而非www.test.com/how-to/articles 尝试了以下操作但没有成功: const myPattern = /^\/(a
const myPattern = /^\/(abc|def|gh|how-to\/articles|xyz){1}/I;
上述内容与www.test.com/how-to/articles
&www.test.com/how-to/articles/
如何调整上面的模式,使其匹配
www.test.com/how-to/articles/
而非www.test.com/how-to/articles
尝试了以下操作但没有成功:
const myPattern = /^\/(abc|def|gh|how-to\/articles\/.*|xyz){1}/I;
const myPattern = /^\/(abc|def|gh|how-to\/articles\/.|xyz){1}/I;
试一试/^\/(?:abc | def | gh | how-to\/文章\/.+| xyz)/i
试一试/(?:abc | def | gh | how-to\/文章\/.+| xyz)/i