简体   繁体   English

URL 提取的正则表达式部分

[英]regular expression part of URL extract

need a little help with extracting part of the URL via regex需要一点帮助来通过正则表达式提取 URL 的一部分

I have URL which looks like this:我有 URL 看起来像这样:

http://www.something.com/offer/1/all-[part to be extracted]-offers-discounts

First parameter is static/fixed ( /offer/ ), second one is number variable ( /1/ ) which is in range of x-xxxxx.第一个参数是静态/固定( /offer/ ),第二个是数字变量( /1/ ),在 x-xxxxx 范围内。

This needs to be 301 redirected to: http://www.something.com/[part to be extracted]这需要301重定向到: http://www.something.com/[part to be extracted]

http://www.something.com/offer/\d+/all-(.*)-offers-discounts

redirect to重定向到

http://www.something.com/$1

Split the Incoming url on "/" if using Java use string.split() take the last index of the returned array in a variable say resultSplit , again split resultSplit on "-" take the second index from the result array and use it for redirection on the new url.如果使用 Java 将传入 url 拆分到“/”上,请使用string.split()在变量中获取返回数组的最后一个索引,例如resultSplit ,再次拆分resultSplit on“-”从结果数组中获取第二个索引并将其用于在新的 url 上重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM