简体   繁体   English

用组替换的RegEx重建

[英]RegEx reconstruction with replace with groups

We are doing URL rewrite and user can type url as 我们正在重写URL,用户可以输入url为

 somesite.com/category6/page.aspx

Now we want to rewrite the url as 现在我们要重写网址为

 somesite.com/6/category/page.aspx.

We already have bunch of regex for url rewrite however replace string is static, we wanted follow the same pattern and not to customize for this particular one. 我们已经有很多用于url重写的正则表达式,但是replace string是静态的,我们希望遵循相同的模式,而不是针对该特定模式进行自定义。

rewrite rule : 重写规则

(category)([0-9]+)(/?.*) (类别)([0-9] +)(/?.*)

parsing : 解析

{R:0} category6/page.aspx {R:0} category6 / page.aspx

{R:1} category {R:1}类别

{R:2} 6 {R:2} 6

{R:3} /page.aspx {R:3} /page.aspx

using the rules : 使用规则

{R:2}/{R:1}{R:3} {R:2} / {R:1} {R:3}

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

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