javascript - 通过正则表达式解析url结构
问题描述
我有一个URL
模式:
product/[cat]/[page].[ext]
产品/类别/page.html
产品/page.html
但是我的正则表达式不能正常工作:
^product\/([\w\d\.\-_\s\'\"\(\)\[\]\-\ۿ](?!.*\.html))*\/([\w\d\.\-_\s\'\"\(\)\[\]\-\ۿ]+\.html+)*\/?$
我想通过一种regEx
模式检测 url 及其参数
我match
在javascript中使用函数
编辑 :
我的路线模式:
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
解决方案
推荐阅读
- javascript - Handlebars JS 将 HTML 处理为字符串
- html - iframe 不工作我该怎么办
- json - 从 JSON RDD 读取数据时出现异常
- c# - 在 Unity C# 中编辑结构值
- java - 程序中的 StackOverflow 错误,我找不到原因
- spring-boot - 如何配置 Spring Boot 不连接到数据库
- angular - 自定义组件 Ionic3 + Angular
- php - PHP 两个数组 - 如果它们不同则插入 - 否则更新
- database - 数据库yii2的输出问题
- rest - Rest API 使用复杂的过滤器获取数据