📄 class1.cs
字号:
using System;
using System.Text.RegularExpressions;
namespace Example_ValidateUrl
{
/// <summary>
/// 验证一个URL的合法性
/// </summary>
class MainTest
{
public bool ValidateUrl(string _strUrl)
{
string patten = @"^http://(www\.){0,1}.+\.(com|net|cn)$"; //正则表达式
Regex r = new Regex(patten); //声明一个Regex对象
Match m = r.Match(_strUrl); //使用Match方法进行匹配
if(m.Success) //匹配成功
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
MainTest t=new MainTest();
string strUrl="http://www.php.net";
Console.WriteLine(t.ValidateUrl(strUrl));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -