Regular Expression Help!

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

    #1

    Regular Expression Help!

    Hi - I'll admit it.. I'm clueless using regular expressions. That's why I
    was hoping someone could help me out a bit. I need to search an html file
    and find strings that are between tags. For example, everything in bewtween
    the <body></body> tag. As you well know, this string could span many lines,
    white spaces, tabs, et.... So I need an expression that will match the
    <body> tag, ingnore EVERYTHING then match the end </body> tag.

    Anyone to the rescue?? :)

    Thanks a lot in advance
    Steve


  • Svend Dyhr Hansen

    #2
    Re: Regular Expression Help!

    Hi,

    I have been using this for doing the job in C#:

    private string getBodyText(str ing inputString)
    {
    string pattern = "<body(<?body>. *)</body>";
    Regex r = new Regex(pattern,
    RegexOptions.Ig noreCase|RegexO ptions.Compiled );
    Match m = r.Match(inputSt ring);
    if (m.Success)
    {
    return m.Groups["body"].Value;
    }
    else
    {
    return inputString;
    }
    }

    Regards,
    Svend

    "Steve Peterson" <fakemail@fakem ail.com> wrote in message
    news:%233Ep2Xfn DHA.2432@TK2MSF TNGP10.phx.gbl. ..[color=blue]
    > Hi - I'll admit it.. I'm clueless using regular expressions. That's why I
    > was hoping someone could help me out a bit. I need to search an html file
    > and find strings that are between tags. For example, everything in[/color]
    bewtween[color=blue]
    > the <body></body> tag. As you well know, this string could span many[/color]
    lines,[color=blue]
    > white spaces, tabs, et.... So I need an expression that will match the
    > <body> tag, ingnore EVERYTHING then match the end </body> tag.
    >
    > Anyone to the rescue?? :)
    >
    > Thanks a lot in advance
    > Steve
    >
    >[/color]


    Comment

    • Steve Peterson

      #3
      Re: Regular Expression Help!

      Did the trick! Thanks!!!
      Steve


      "Svend Dyhr Hansen" <svend@nospam.d k> wrote in message
      news:OypGnjinDH A.1884@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Hi,
      >
      > I have been using this for doing the job in C#:
      >
      > private string getBodyText(str ing inputString)
      > {
      > string pattern = "<body(<?body>. *)</body>";
      > Regex r = new Regex(pattern,
      > RegexOptions.Ig noreCase|RegexO ptions.Compiled );
      > Match m = r.Match(inputSt ring);
      > if (m.Success)
      > {
      > return m.Groups["body"].Value;
      > }
      > else
      > {
      > return inputString;
      > }
      > }
      >
      > Regards,
      > Svend
      >
      > "Steve Peterson" <fakemail@fakem ail.com> wrote in message
      > news:%233Ep2Xfn DHA.2432@TK2MSF TNGP10.phx.gbl. ..[color=green]
      > > Hi - I'll admit it.. I'm clueless using regular expressions. That's why[/color][/color]
      I[color=blue][color=green]
      > > was hoping someone could help me out a bit. I need to search an html[/color][/color]
      file[color=blue][color=green]
      > > and find strings that are between tags. For example, everything in[/color]
      > bewtween[color=green]
      > > the <body></body> tag. As you well know, this string could span many[/color]
      > lines,[color=green]
      > > white spaces, tabs, et.... So I need an expression that will match the
      > > <body> tag, ingnore EVERYTHING then match the end </body> tag.
      > >
      > > Anyone to the rescue?? :)
      > >
      > > Thanks a lot in advance
      > > Steve
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Fergus Cooney

        #4
        Re: Regular Expression Help!

        Hi Steve,

        You could host the Microsoft Web Browser (ShDocVw) and use the Document
        Object Model to do the work for you.

        In your case it would be
        Browser.Documen t.Body.InnerHtm l
        (just as it would in Javascript or VbScript).

        Regards,
        Fergus


        Comment

        Working...