匹配URL

使用一个不错的正则表达式来配对一个正确的url.

string reg = @"(?i)(http://|https://)?(w+.){1,3}(com(.cn)?|cn|net|info|org|us|tk)"; 比较通用
            string reg = @"(?i)(http://|https://)?(w+.){1,3}(com(.cn)?|cn|net|info|org|us|tk)";
            Regex r = new Regex(reg);

            textEditUrl.Text = textEditUrl.Text.Trim();
            Match match = r.Match(textEditUrl.Text);
            if (!match.Success)
            {
                CustomControls.MessageErrDlg dlg = new CustomControls.MessageErrDlg();
                dlg.Text = "Remote Command Failed";
                dlg.ShowDialog();

                textEditUrl.Text = "http://";
            }
原文地址:https://www.cnblogs.com/qq702368956/p/6587886.html