使用正则表达式使用C#Visual Studio解析代理的最有效方法?

使用正则表达式使用C#Visual Studio解析代理的最有效方法?,c#,regex,visual-studio-2012,C#,Regex,Visual Studio 2012,使用VisualStudio和C#,如何使用正则表达式来检索代理,以最好的方式解析给定的已下载html字符串 namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public string stringVar { ge

使用VisualStudio和C#,如何使用正则表达式来检索代理,以最好的方式解析给定的已下载html字符串

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public string stringVar { get; set; }

        private void button1_Click(object sender, EventArgs e)
        {
            WebClient wc = new WebClient();

            stringVar = wc.DownloadString("http://somewebsitewithproxies.com/");

            // some regex operation on stringVar here perhaps?

            textBox1.Text = // ???

        }


    }
}
我将使用正则表达式:

\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}[:]\d{1,5}
我希望对变量“stringVar”进行解析,并将代理设置为textBox1。在整个按钮点击过程中,这是否足够简单


提前感谢。

您的正则表达式可以通过重复简化。以下代码用于匹配代理模式

string proxyPattern = @"\d{1,3}(\.\d{1,3}){3}:\d{1,5}";
Match match = Regex.Match(str, proxyPattern);
if (match.Success)
{
    Console.WriteLine(match.Groups[0].Value);
}

问题不清楚。答案“是”能满足您的期望吗?很抱歉,实际上我想知道怎么做。具体怎么做?如何从下载的html中解析代理并在textbox1中打印它们。很抱歉不能说得更清楚,我想不出任何其他方法来询问如何获取下载的html源代码并解析代理。你试过谷歌吗?你真的认为没有关于如何获取页面和使用正则表达式的文章吗?@POPOL谢谢你的回复。我怎样才能将其纳入我在上面问题中使用的代码中?例如,如果使用DownloadString下载的html源代码设置为一个名为“stringVar”的变量,我如何使用您的示例解析代理并将其设置为textbox1?