首页 > 代码库 > 匹配URL

匹配URL

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

string reg = @"(?i)(http://|https://)?(\w+\.){1,3}(com(\.cn)?|cn|net|info|org|us|tk)\b"; 比较通用
            string reg = @"(?i)(http://|https://)?(\w+\.){1,3}(com(\.cn)?|cn|net|info|org|us|tk)\b";
            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://";
            }

 

匹配URL