使用一个不错的正则表达式来配对一个正确的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://";
            }

 

posted on 2017-03-20 12:50  chifandeyu  阅读(181)  评论(0编辑  收藏  举报