【发布时间】:2020-10-12 01:54:02
【问题描述】:
我有一个 URL 模式:
product/[cat]/[page].[ext]
产品/类别/page.html
product/page.html
但是我的正则表达式不能正常工作:
^product\/([\w\d\.\-_\s\'\"\(\)\[\]\-\ۿ](?!.*\.html))*\/([\w\d\.\-_\s\'\"\(\)\[\]\-\ۿ]+\.html+)*\/?$
我想通过一个regEx模式检测url及其参数
我在javascript中使用match函数
编辑:
我的路线模式:
product/cat?/page.html?
我想用这种模式制作regEx
? 在这个模式中意味着这个部分是可选的
例如:
makeRegEx('product/cat?/page.html?')
结果:
^product\/([\w\d\.\-_\s\'\"\(\)\[\]\-\ۿ](?!.*\.html))*\/([\w\d\.\-_\s\'\"\(\)\[\]\-\ۿ]+\.html+)*\/?$
当路由:product/computer/ram.html
正则表达式检测:
cat = computer
page = ram.html
【问题讨论】:
-
"product/cat/page.html".split(/[./]/) -
这些奇怪的字符“ۿ”是什么?正则表达式的目标是什么?检查它是否是特定路线?
-
@Kaddath \u0600-\u06FF,是的,通过模式列表检查 url 以了解到目的地的路线
-
@Andreas 正则表达式更快
-
“正则表达式更快” - 这只是一个意见
标签: javascript regex url