-2

Using Visual Studio and C#, How can I do the best way to parse a given string of downloaded html using regex to retrieve the proxies?

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 = // ???

        }


    }
}

I will be using the regex expression:

\d{1,3}[.]\d{1,3}[.]\d{1,3}[.]\d{1,3}[:]\d{1,5}

I would like to have the variable 'stringVar' be parsed and the proxies set to textBox1. Would this be easy enough to do within the entire button click?

Thanks in advance.

4

1 回答 1

0

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

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);
}
于 2013-07-10T02:13:48.860 回答