正则表达式

MSDN:

http://msdn.microsoft.com/zh-cn/library/ae5bf541(VS.80).aspx

使用RegexBuddy 工具可以测试正则表达式是否正确。其中正则表达式一对括弧,则会产生一对Group组。(括弧本身是正则表达式的语法除外)。

一般代码书写如下:

string url="http://www.baidu.com:9000/mytest/"
Regex regex = new Regex(@"^(https?://)?((w+.)+w+)(:d+)?(/?)([w/]+)?$");
if (regex.IsMatch(url))
{
Match match = regex.Match(url);
string uri_http = match.Groups[1].Value;
string uri_slash = match.Groups[5].Value;
string uri_end = match.Groups[6].Value;
if (string.IsNullOrEmpty(uri_http))
{

}
if (string.IsNullOrEmpty(uri_end))
{

}
}
原文地址:https://www.cnblogs.com/luohengstudy/p/3820112.html