Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/313.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
Java Url重写正则表达式-不匹配_Java_Regex_Url Rewriting_Tuckey Urlrewrite Filter - Fatal编程技术网

Java Url重写正则表达式-不匹配

Java Url重写正则表达式-不匹配,java,regex,url-rewriting,tuckey-urlrewrite-filter,Java,Regex,Url Rewriting,Tuckey Urlrewrite Filter,我有一个用于url重写的正则表达式: <from>^/page/([0-9]+)/order/(.*)/by/(.*)/composition/(.*)/location/(.*)/price_min/(.*)/price_max/(.*)/industry/(.*)/type/(.*)$</from> <to>/page=$1&order=$2&by=$3&composition=$4&location_id=$5&p

我有一个用于url重写的正则表达式:

<from>^/page/([0-9]+)/order/(.*)/by/(.*)/composition/(.*)/location/(.*)/price_min/(.*)/price_max/(.*)/industry/(.*)/type/(.*)$</from>
<to>/page=$1&order=$2&by=$3&composition=$4&location_id=$5&price_min=$6&price_max=$7&industry_id=$8&type_id=$9</to>
^/page/([0-9]+)/order/(.*)/by/(.*)/composition/(.*)/location/(.*)/price_-min/(.*)/price_-max/(.*)/industry/(.*)/type/(.*)$
/页面=$1&订单=$2&按=$3&组合=$4&位置id=$5&价格最低=$6&价格最高=$7&行业id=$8&类型id=$9
我想匹配下面的URL,但没有匹配项

/第/2页/订单/id/by/desc/composition/1/location/none/price\u min/2/price\u max/2/industry/2/type/3


考虑使用以下方法:

^/page/([0-9]+)/order/(.+?)/by/(.+?)/composition/(.+?)/location/(.+?)/price_min/(.+?)/price_max/(.+?)/industry/(.+?)/type/(.+?)$
你的正则表达式有两件事:

  • 您应该使用
    +
    而不是
    *
    ,因为
    /
    /
    之间总会有数据
  • 您应该添加
    ,这意味着它将是非贪婪的。它相当于写入
    ([^/]+)
    ,这意味着
    /
    以外的任何字符多次匹配

  • 试着用非贪婪的
    *
    替换贪婪的
    *?
    哦,好的,谢谢你,我现在更明白了,我今天晚些时候再试试这个好的,很好,谢谢你,我刚刚补充了一件事&应该是&;