Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 匹配特定的url模式_Javascript_Regex_Ecmascript 6 - Fatal编程技术网

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