المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : regex problem



C# Programming
01-16-2010, 12:52 AM
Hi,
my regex works fine in a regextest tool its just only when i try to filter the content via c# it doesnt work. here is my code


string fName = @"data.txt";//path to text file
StreamReader testTxt = new StreamReader(fName);
string allRead = testTxt.ReadToEnd();//Reads the whole text file to the end
testTxt.Close(); //Closes the text file after it is fully read.
string regMatch = @"(?<=\<div class=""middleadimggold""\>).*?(?=\</div\>)"; //string to search for inside of text file. It is case sensitive.
if (Regex.IsMatch(allRead, regMatch))//If the match is found in allRead
{
Console.WriteLine("found\n");

}
else
{
Console.WriteLine("not found\n");
}

part of the content that should match


<div class="middleadimggold">



<a class="asdf" href="http://www.asdf">
asdf</a>
<p>
asdf</p>
<p>asdf</p><p>asdf</p>

<p><span class="blue">asdf</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="de" href="http://www.4asdf"><span class="a">(See on map)</span></a></p>

<p><span class="blue">asdf</span></p>



<span class="xx">


asdf
</span>

</div>


please note the spacing in the content, not sure if it matters?