Regex beginner problem


G

Ginola

Hi,

I have a beginner of C# and I need to fix the bug for someone!!

I have the codes like this

Regex re = new Regex(@"<TR VALIGN=top><TD></TD>.*?</TD></TR>");
MatchCollection theMatches = re.Matches(content);
ArrayList list = new ArrayList();
foreach (Match theMatch in theMatches)

for the string at the bottom...
some how it couldn't get any value ( couldn't get into the foreach
loop )

Does howone point out the problem ??
Please help me, thanks.


----------------------------------------
<TR VALIGN=top><TD></TD><TD><IMG SRC="/icons/ecblank.gif" BORDER=0
HEIGHT=1 WIDTH=16 ALT=""><FONT SIZE=1
FACE="Verdana"><li><br></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
FACE="Verdana"><A
HREF="/webcorannc.nsf/1c5fa13a6eee416848256db2000356de/88c789fbb737109c48256dc1002fbbcf?OpenDocument">Oct
16 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
FACE="Verdana"><A
HREF="/webcorannc.nsf/1c5fa13a6eee416848256db2000356de/88c789fbb737109c48256dc1002fbbcf?OpenDocument">Sales
in open market at own discretion on 15/10/2003. 8,408,000 warrants
pertaining to director/substantial shareholder CHUA HAI
KUEY</A></FONT></TD><TD><IMG SRC="/icons/ecblank.gif" BORDER=0
HEIGHT=16 WIDTH=1 ALT=""></TD></TR>

<TR VALIGN=top><TD></TD><TD><IMG SRC="/icons/ecblank.gif" BORDER=0
HEIGHT=1 WIDTH=16 ALT=""><FONT SIZE=1
FACE="Verdana"><li><br></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
FACE="Verdana"><A
HREF="/webcorannc.nsf/1c5fa13a6eee416848256db2000356de/71ee5070be7b3a1d48256dc1002f178f?OpenDocument">Oct
16 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
FACE="Verdana"><A
HREF="/webcorannc.nsf/1c5fa13a6eee416848256db2000356de/71ee5070be7b3a1d48256dc1002f178f?OpenDocument">Sales
in open market at own discretion on 15/10/2003. 8,408,000 warrants
pertaining to director/substantial shareholder CHUA HAI
KUEY</A></FONT></TD><TD><IMG SRC="/icons/ecblank.gif" BORDER=0
HEIGHT=16 WIDTH=1 ALT=""></TD></TR>

<TR VALIGN=top><TD></TD><TD><IMG SRC="/icons/ecblank.gif" BORDER=0
HEIGHT=1 WIDTH=16 ALT=""><FONT SIZE=1
FACE="Verdana"><li><br></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
FACE="Verdana"><A
HREF="/webcorannc.nsf/1c5fa13a6eee416848256db2000356de/11404ba32a1043fc48256db3003b1e98?OpenDocument">Oct
02 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
FACE="Verdana"><A
HREF="/webcorannc.nsf/1c5fa13a6eee416848256db2000356de/11404ba32a1043fc48256db3003b1e98?OpenDocument">Others
on 01/10/2003. 4,320,000 shares pertaining to substantial shareholder
CHUA KON SENG</A></FONT></TD><TD><IMG SRC="/icons/ecblank.gif"
BORDER=0 HEIGHT=16 WIDTH=1 ALT=""></TD></TR>

Ginola
 
Ad

Advertisements

C

Chris R. Timmons

(e-mail address removed) (Ginola) wrote in
Hi,

I have a beginner of C# and I need to fix the bug for someone!!

I have the codes like this

Regex re = new Regex(@"<TR VALIGN=top><TD></TD>.*?</TD></TR>");
MatchCollection theMatches = re.Matches(content);
ArrayList list = new ArrayList();
foreach (Match theMatch in theMatches)

for the string at the bottom...
some how it couldn't get any value ( couldn't get into the
foreach loop )

Ginola,

You need to have your regex process the HTML as a single line of
text:

Regex re = new Regex(@"<TR VALIGN=top><TD></TD>.*?</TD></TR>",
RegexOptions.Singleline);


Hope this helps.

Chris.
 
Ad

Advertisements

R

Richard A. Lowe

You need to specify the Singleline option, which will allow the "." in your
expression to match across multiple lines:

Regex re = new Regex(@"<TR
VALIGN=top><TD></TD>.*?</TD></TR>",RegexOptions.Singleline);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top