Scott
Scott

Reputation: 13941

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?

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.

Upvotes: 0

Views: 133

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727137

Use "http://([^/]+)/sponsor/([^/]+)/reo/news" as your regexp.

Use and "http://$1/reo/news?brokerId=$2"as your replacement string.

I tried your example on .NET Regex Tester, and it produced the desired output.

Upvotes: 1

Related Questions