using System;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
namespace Working
{
class Program4
{
static string errorurl =
"http://www.realtor.ca/propertyDetails.aspx?propertyId=8692663";
static void Main(string[] args)
{
string s;
s = getWebpageContent(errorurl);
s = removeNewLineCharacters(s);
getFields(s);
Console.WriteLine("End");
}
public static void getFields(string html)
{
Match m;
string fsRE = @"ismeasurement.*?>.*?(\d+).*?sqft";
m = Regex.Match(html, fsRE, RegexOptions.IgnoreCase);
}
private static string removeNewLineCharacters(string str)
{
string[] charsToRemove = new string[] { "\n", "\r" };
foreach (string c in charsToRemove)
{
str = str.Replace(c, "");
}
return str;
}
static string getWebpageContent(string url)
{
WebClient client = new WebClient();
client.Headers.Add("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;
.NET CLR 1.0.3705;)");
Stream data = client.OpenRead(url);
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd();
data.Close();
reader.Close();
return s;
}
}
}
該程序掛起。當我刪除RegexOptions.IgnoreCase選項或 時,它會正確運行,當我刪除對removeNewLineCharacters()函數的調用時。
請問有人能告訴我發生了什麼事嗎?爲什麼這C#正則表達式崩潰我的程序?
順便說一下,你的程序不會崩潰。它掛起。 – Foole 2010-03-20 22:26:12