Click here to Skip to main content
15,921,279 members
Home / Discussions / C#
   

C#

 
QuestionRegex Problem,Extracting text from Table Pin
NaveenHS21-Jul-10 2:03
NaveenHS21-Jul-10 2:03 
Hello Everyone,

I am trying to extract the contents of the table from a static HTML file.
Program is almost giving the expected output.

Program :-
class Program
	{
		static void Main()
		{
			StreamReader str = new StreamReader("C:\\AllRoles.html");
			string SFile = str.ReadToEnd();
						
		    Regex regex = new Regex(
				@"<tr>(\s* <td[^>]*>  \s* (?<value>[^<]*?) \s* </td> )+ \s*</tr>",
		 		RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);


			 foreach( Match m in regex.Matches( SFile ) )
			 {
				foreach( Capture item in m.Groups["value"].Captures ) {

				Console.WriteLine( item.Value );
			}
			
				Console.WriteLine( );
			}
				Console.ReadLine();
		}
	}



I am facing one problem there is a comment in between the table content


HTML File :-


<table border="0" cellpadding="5" cellspacing="0" width="100%">
            <tbody><tr>
            <td class="columnheading" nowrap="nowrap">Last Name</td>
            <td class="columnheading" nowrap="nowrap">First Name</td>
           <td class="columnheading" nowrap="nowrap">Role</td>
           <td class="columnheading">Term</td>
           <td class="columnheading">Company</td>
           </tr>
           <tr>
           <td valign="top">

           <!-- Logic Here-->


           Gottlieb

           </td>
           <td valign="top">Pradep</td>
           <td valign="top">President

           </td>
           <td valign="top">8/15/2009 - 9/1/2010</td>
           <td valign="top">DSCMIT</td>

           </tr>
           <tr>
           <td valign="top">
           <!-- Logic Here-->


           Rajesh

           </td>
           <td valign="top">H</td>
           <td valign="top"> President

           </td>
           <td valign="top">8/15/2009 - 8/14/2010</td>
           <td valign="top">BHSIT</td>
           </tr>



I am getting the Output as

Last Name
First Name
Role
Term
Company

and it stops at this line <!-- Logic Here-->

Can anyone please help me to solve this problem.

Thanking you,
Naveen HS
AnswerRe: Regex Problem,Extracting text from Table Pin
Luc Pattyn21-Jul-10 2:13
sitebuilderLuc Pattyn21-Jul-10 2:13 
QuestionFunction Call Mechanism Pin
califax2k20-Jul-10 23:15
califax2k20-Jul-10 23:15 
AnswerRe: Function Call Mechanism Pin
PIEBALDconsult21-Jul-10 2:37
mvePIEBALDconsult21-Jul-10 2:37 
QuestionHow to call C# function from unmanaged C++ code.? Pin
deadlyabbas20-Jul-10 19:58
deadlyabbas20-Jul-10 19:58 
AnswerRe: How to call C# function from unmanaged C++ code.? Pin
Luc Pattyn20-Jul-10 23:14
sitebuilderLuc Pattyn20-Jul-10 23:14 
AnswerRe: How to call C# function from unmanaged C++ code.? Pin
Pete O'Hanlon21-Jul-10 2:34
mvePete O'Hanlon21-Jul-10 2:34 
QuestionOpening a binary document from db is failing Pin
seeism20-Jul-10 19:04
seeism20-Jul-10 19:04 
AnswerRe: Opening a binary document from db is failing Pin
Abhinav S20-Jul-10 19:12
Abhinav S20-Jul-10 19:12 
GeneralRe: Opening a binary document from db is failing Pin
seeism20-Jul-10 19:20
seeism20-Jul-10 19:20 
GeneralRe: Opening a binary document from db is failing Pin
Goutam Patra20-Jul-10 20:06
professionalGoutam Patra20-Jul-10 20:06 
GeneralRe: Opening a binary document from db is failing Pin
seeism20-Jul-10 20:22
seeism20-Jul-10 20:22 
GeneralRe: Opening a binary document from db is failing Pin
seeism20-Jul-10 20:42
seeism20-Jul-10 20:42 
GeneralRe: Opening a binary document from db is failing Pin
seeism21-Jul-10 18:24
seeism21-Jul-10 18:24 
GeneralRe: Opening a binary document from db is failing Pin
Goutam Patra21-Jul-10 20:24
professionalGoutam Patra21-Jul-10 20:24 
GeneralRe: Opening a binary document from db is failing Pin
seeism21-Jul-10 22:23
seeism21-Jul-10 22:23 
GeneralRe: Opening a binary document from db is failing Pin
Goutam Patra21-Jul-10 23:05
professionalGoutam Patra21-Jul-10 23:05 
GeneralRe: Opening a binary document from db is failing Pin
seeism21-Jul-10 23:14
seeism21-Jul-10 23:14 
Question.exe update Pin
padmanabhan N20-Jul-10 18:49
padmanabhan N20-Jul-10 18:49 
AnswerRe: .exe update Pin
Abhinav S20-Jul-10 19:13
Abhinav S20-Jul-10 19:13 
AnswerRe: .exe update Pin
Nagy Vilmos20-Jul-10 19:17
professionalNagy Vilmos20-Jul-10 19:17 
GeneralRe: .exe update Pin
padmanabhan N20-Jul-10 21:13
padmanabhan N20-Jul-10 21:13 
QuestionDataColumn question Pin
Richard Blythe20-Jul-10 14:23
Richard Blythe20-Jul-10 14:23 
AnswerRe: DataColumn question Pin
Dan Mos20-Jul-10 15:22
Dan Mos20-Jul-10 15:22 
QuestionHandling Multiple Exception Types Pin
Matt U.20-Jul-10 13:31
Matt U.20-Jul-10 13:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.