看到很多说正则,正则具体怎么写,求教!

解决方案 »

  1.   

            public bool urlCheck(string http)
            {
                return Regex.IsMatch(http, ("^http\\"));
            }
        这个正则是我乱整的,求正确解答!
      

  2.   

    url的正则网上多的是,有简单的,有复杂的,楼主要学会搜索呀
      

  3.   

    新建一个按钮和文本框  
    按钮单击判断是否正确
    string urlFormat = @"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"; //定义规则
    Match url = Regex.Match(tbxUrl.Text, urlFormat);   //获取正则匹配的结果
                if (url.Success)   //判断并输出验证结果
                {
                    MessageBox.Show("yes");
                }
                else
                {
                    MessageBox.Show("no");
                }
      

  4.   

    正则:http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
      

  5.   

    http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
      

  6.   


    Regex reg = new Regex(@"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
    MessageBox.Show(reg.IsMatch("http://a.com").ToString());
      

  7.   


     string reg = @"^(http(s)?:\/\/)?(www\.)?[\w-]+(\.\w{2,4})?\.\w{2,4}?(\/)?$";
                    Regex r = new Regex(reg);
                    //给网址去所有空格
                    string urlStr = webresourceaddress.Trim();
                    Match m = r.Match(urlStr);                //判断是否带http://
                    if (!m.Success)
                        return false;
                    //给不带http://开头的加上 
                    urlStr = urlStr.Replace("http://", "");
                    urlStr = urlStr.Insert(0, "http://");
      

  8.   


    /// <summary>
            /// 检测串值是否为合法的网址格式
            /// </summary>
            /// <param name="strValue">要检测的String值</param>
            /// <returns>成功返回true 失败返回false</returns>
            public static bool CheckIsUrlFormat(string strValue)
            {
                return Utility.CheckIsFormat(@"(http://)?([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", strValue);
            }/// <summary>
            /// 检测串值是否为合法的格式
            /// </summary>
            /// <param name="strRegex">正则表达式</param>
            /// <param name="strValue">要检测的String值</param>
            /// <returns>成功返回true 失败返回false</returns>
    public static bool CheckIsFormat(string strRegex,string strValue)
    {
    if(strValue != null && strValue.Trim() != "")
    {
    Regex re = new Regex(strRegex);
    if (re.IsMatch(strValue))
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    return false;
    }
      

  9.   

    哪需要正则这么麻烦,直接用System.Uri就可以了。Uri.IsWellFormedUriString("http://host.com/page.html", UriKind.Absolute);如果需要再判断是否HTTP协议,可再使用Uri.CheckSchemeName方法验证。
      

  10.   

    http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
      

  11.   

    楼上的都是只是判断www形式的,比如我http://localhost/XXXX或者http://192.168.1.1/xxxx就不行的啊