Regex beginner problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ginola

    #1

    Regex beginner problem

    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(cont ent);
    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/1c5fa13a6eee416 848256db2000356 de/88c789fbb737109 c48256dc1002fbb cf?OpenDocument ">Oct
    16 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
    FACE="Verdana"> <A
    HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/88c789fbb737109 c48256dc1002fbb cf?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/1c5fa13a6eee416 848256db2000356 de/71ee5070be7b3a1 d48256dc1002f17 8f?OpenDocument ">Oct
    16 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
    FACE="Verdana"> <A
    HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/71ee5070be7b3a1 d48256dc1002f17 8f?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/1c5fa13a6eee416 848256db2000356 de/11404ba32a1043f c48256db3003b1e 98?OpenDocument ">Oct
    02 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
    FACE="Verdana"> <A
    HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/11404ba32a1043f c48256db3003b1e 98?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
  • Chris R. Timmons

    #2
    Re: Regex beginner problem

    ginola@fake.ema il.com (Ginola) wrote in
    news:3fa5270a.7 45772@msnews.mi crosoft.com:
    [color=blue]
    > 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(cont ent);
    > 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 )[/color]

    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.Si ngleline);


    Hope this helps.

    Chris.
    -------------
    C.R. Timmons Consulting, Inc.

    Comment

    • Richard A. Lowe

      #3
      Re: Regex beginner problem

      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>",RegexOptio ns.Singleline);

      --
      Veuillez m'excuser, mon Français est très pauvre. Cependant, si vous voyez
      mauvais C #, c'est mon défaut!
      "Ginola" <ginola@fake.em ail.com> wrote in message
      news:3fa5270a.7 45772@msnews.mi crosoft.com...[color=blue]
      > 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(cont ent);
      > 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
      >[/color]
      HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/88c789fbb737109 c48256
      dc1002fbbcf?Ope nDocument">Oct[color=blue]
      > 16 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
      > FACE="Verdana"> <A
      >[/color]
      HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/88c789fbb737109 c48256
      dc1002fbbcf?Ope nDocument">Sale s[color=blue]
      > 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
      >[/color]
      HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/71ee5070be7b3a1 d48256
      dc1002f178f?Ope nDocument">Oct[color=blue]
      > 16 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
      > FACE="Verdana"> <A
      >[/color]
      HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/71ee5070be7b3a1 d48256
      dc1002f178f?Ope nDocument">Sale s[color=blue]
      > 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
      >[/color]
      HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/11404ba32a1043f c48256
      db3003b1e98?Ope nDocument">Oct[color=blue]
      > 02 2003</A></FONT></TD><TD><FONT SIZE=1 COLOR="0000ff"
      > FACE="Verdana"> <A
      >[/color]
      HREF="/webcorannc.nsf/1c5fa13a6eee416 848256db2000356 de/11404ba32a1043f c48256
      db3003b1e98?Ope nDocument">Othe rs[color=blue]
      > 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[/color]


      Comment

      Working...