[英]Regular expression help for URL
I have a URL like this: 我有这样的网址:
http://www.domain.com/sponsor/xxxxx/reo/news
It needs to end up being rewritten to: 它最终需要重写为:
http://www.domain.com/reo/news?brokerId=xxxxx
I'm terrible at regular expressions. 我对正则表达式很糟糕。 How can I extrapolate the "xxxxxx" from the source URL and transform the string to the end result?
如何从源URL推断“ xxxxxx”并将字符串转换为最终结果?
I don't really need much help creating the end result, that's pretty trivial, but if there's a nice, clean way to do it with RegEx versus raw string manipulation, that'd be nice to know about. 我真的不需要太多帮助来创建最终结果,这是微不足道的,但是如果有一种很好的,干净的方法来使用RegEx和原始字符串操作,那真是太好了。
Use "http://([^/]+)/sponsor/([^/]+)/reo/news"
as your regexp. 使用
"http://([^/]+)/sponsor/([^/]+)/reo/news"
作为您的正则表达式。
Use and "http://$1/reo/news?brokerId=$2"
as your replacement string. 使用
"http://$1/reo/news?brokerId=$2"
作为替换字符串。
I tried your example on .NET Regex Tester , and it produced the desired output. 我在.NET Regex Tester上尝试了您的示例,它产生了所需的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.