regex problem [modified]
-
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>
<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?
modified on Thursday, January 14, 2010 10:06 PM
-
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>
<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?
modified on Thursday, January 14, 2010 10:06 PM
-
ok this fixed the problem if (Regex.IsMatch(allRead, regMatch, RegexOptions.Singleline) singleline option that is. thanks for nothing
-
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>
<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?
modified on Thursday, January 14, 2010 10:06 PM