简体   繁体   English

使用正则表达式获取不含查询字符串的网址

[英]Regular expression to get Url without Query string

I am looking for a way to parse URL without queryString using Regular expression. 我正在寻找一种使用正则表达式来解析不带queryString的URL的方法。

i have url like "http://abc.com/csd?/aaa/bbb" 我有类似"http://abc.com/csd?/aaa/bbb"网址

expected is like "http://abc.com/csd" 预期就像"http://abc.com/csd"

Anybody help me on this. 有人在这方面帮助我。

如果只需要查询字符串之前的所有内容:

^[^?]+

You could use Substring and IndexOf 您可以使用SubstringIndexOf

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. 虽然这并不完全在你的问题中所述的要求符合,它可能是一个更简单的方法-如果实际执行并不需要是正则表达式。

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

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

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