开发者

Regular expression to get Url without Query string

开发者 https://www.devze.com 2023-04-09 03:06 出处:网络
I am looking for a way to parse URL without queryString using Regular expression. i have url like \"http://abc.com/csd?/aaa/bb开发者_运维问答b\"

I am looking for a way to parse URL without queryString using Regular expression.

i have url like "http://abc.com/csd?/aaa/bb开发者_运维问答b"

expected is like "http://abc.com/csd"

Anybody help me on this.


If you just want everything before the query string:

^[^?]+


Regex r = new Regex("(^[^?]+)");
Match m = r.Match("http://example.com/csd?/aaa/bbb");
// m.Groups[0].Value is your URL


You could use Substring and IndexOf

var someString = "http://abc.com/csd?/aaa/bbb";
someString.Substring(0, someString.IndexOf('?') - 1);

while this does not fully comply with the requirements stated in your question, it might be an easier approach - if actual implementation does not need to be RegEx.

0

精彩评论

暂无评论...
验证码 换一张
取 消