*******高分求一正则*********
最近在做一项目, 涉及到URL重写:
正则1:<rewrite url="^/jing/j(\d+)g(\d+)/?$" to="~/index.aspx?shopid=$1&pageno=$2" />
正则2:<rewrite url="^/jing/(\w+)/?$" to="~/index.aspx?gscope=$1" />
我期望的结果是:
输入/jing/j1g1/用正则1去匹配
输入/jing/chineses/用正则2去匹配
问题:
我现在输入/jing/chineses/却被“正则1”匹配住了,有什么办法处理:如果/jing/后面的第二级目录没有数字就用正则2匹配,否则正则1匹配?如何修改上面的正则呢?
------最佳解决方案--------------------正则2改为
<rewrite url="^/jing/([a-zA-Z\u4e00-\u9fa5]+)/?$" to="~/index.aspx?gscope=$1" />
------其他解决方案--------------------正则2:<rewrite url="^/jing/([A-Za-z]+)/?$" to="~/index.aspx?gscope=$1" />
正则1:<rewrite url="^/jing/([0-9A-Za-z]+)/?$" to="~/index.aspx?gscope=$1" />
把正则2设置在前面,匹配不到,自然就匹配正则1。
------其他解决方案-------------------- <rewrite url="^/jing/p([\d+])/?$" to="~/page/index.aspx?price=$1" />
------其他解决方案--------------------<rewrite url="^/jing/\w+?([\d+])/?$" to="~/page/index.aspx?price=$1" />
------其他解决方案--------------------mark
------其他解决方案--------------------null
------其他解决方案--------------------/jing/chineses/不可能被^/jing/j(\d+)g(\d+)/?$匹配
------其他解决方案--------------------楼主意思是说^/jing/j(\d+)g(\d+)/?$能匹配到/jing/chineses/
下面别用\w+用[a-zA-Z]
------其他解决方案--------------------写错了,我把问题再描述下,
===================================================
做一项目, 涉及到URL重写:
正则1:<rewrite url="^/jing/j(\d+)g(\d+)/?$" to="~/index.aspx?shopid=$1&pageno=$2" />
正则2:<rewrite url="^/jing/(\w+)/?$" to="~/index.aspx?gscope=$1" />
我期望的结果是:
输入/jing/j1g1/用正则1去匹配
输入/jing/chineses/用正则2去匹配
问题:
我现在输入/jing/j1/却被“正则2”匹配住了,有什么办法处理:如果/jing/后面的第二级目录有数字就用正则1匹配,如果是全英文就被正则2匹配?如何修改上面的正则呢?
------其他解决方案--------------------还有一个小问题:
<rewrite url="^/jing/(p[\d+])/?$" to="~/page/index.aspx?price=$1" />
假如输入:/jing/p1/能匹配到
但获取的参数是:p1
我怎么才能只获取数字:1呢?
------其他解决方案--------------------hjywyj回复的会有一个问题:<rewrite url="^/jing/p([\d+])/?$" to="~/page/index.aspx?price=$1" />
必须输入url: /jing/p/才能匹配上