Regex help

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

    #1

    Regex help

    I need help with a regular expression that will pull the
    title and all the meta tags held in the head section of an
    HTML file (including the head tags). I want to exclude
    everything else such as link tags, script tags, etc. I
    have a pretty big process that pulls this stuff now using
    simple Regex expressions, but I know I'm not using the
    Regex's to their fullest. . .
  • Michael Lippert

    #2
    Re: Regex help

    "JKJ" <jeremy.k.johns on@mchsi.com> wrote in news:004b01c344 ac$99d48010
    $a501280a@phx.g bl:
    [color=blue]
    > I need help with a regular expression that will pull the
    > title and all the meta tags held in the head section of an
    > HTML file (including the head tags). I want to exclude
    > everything else such as link tags, script tags, etc. I
    > have a pretty big process that pulls this stuff now using
    > simple Regex expressions, but I know I'm not using the
    > Regex's to their fullest. . .
    >[/color]

    I think you need to explain what you want a little more. What exactly is
    the input to the regular expression, and what are you expecting as the
    output? Perhaps a simple example and or a sample of what you're doing now?

    Comment

    • David Elliott

      #3
      Re: Regex help

      Here is an example of what I have done with an explaination

      public static MatchCollection HtmlMatchCollec tion(string input, string matchstr)
      {
      string expression;

      expression = HttpUtilities.F ullHtmlExpressi on(matchstr);
      MatchCollection mc = Regex.Matches(i nput, expression,
      RegexOptions.Mu ltiline |
      RegexOptions.Ig noreCase |
      RegexOptions.Ig norePatternWhit espace);

      return mc;
      }

      public static string FullHtmlExpress ion(string str)
      {
      /* Example
      * <td colspan=2><img src="/images/b.gif" alt="" width="1" height="25"></td>
      *
      * data1 ==> colSpan=2
      * data2 ==> <img src="/images/b.gif" alt="" width="1" height="25">
      *
      */
      string expression =
      "<" + str + // (?# Match the character sequence <"str")
      "(?<data1>. *?)" + // (?# Capture the characters between <"str" and > )
      ">" + // (?# Match the > character )
      "(?<data2>. *?)" + // (?# Capture the characters between <"str"> and </"str">)
      "</" + str + ">" ; // (?# Match the closing </"str">)

      return expression;
      }

      Cheers,
      Dave


      On Fri, 18 Jul 2003 12:37:02 -0700, Michael Lippert <mlippert255@ya hoo.com> wrote:
      [color=blue]
      >"JKJ" <jeremy.k.johns on@mchsi.com> wrote in news:004b01c344 ac$99d48010
      >$a501280a@phx. gbl:
      >[color=green]
      >> I need help with a regular expression that will pull the
      >> title and all the meta tags held in the head section of an
      >> HTML file (including the head tags). I want to exclude
      >> everything else such as link tags, script tags, etc. I
      >> have a pretty big process that pulls this stuff now using
      >> simple Regex expressions, but I know I'm not using the
      >> Regex's to their fullest. . .
      >>[/color]
      >
      >I think you need to explain what you want a little more. What exactly is
      >the input to the regular expression, and what are you expecting as the
      >output? Perhaps a simple example and or a sample of what you're doing now?[/color]


      Comment

      Working...