Retrieve tag A from html

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

    #1

    Retrieve tag A from html

    Hi.

    I need a regular expression to extract all tag A from HTML
    code. I need the href and text as two disting objects.

    Suggestions?

    Thx! ;-)
    Matteo Migliore.
  • Martin Honnen

    #2
    Re: Retrieve tag A from html

    Matteo Migliore wrote:
    I need a regular expression to extract all tag A from HTML
    code. I need the href and text as two disting objects.
    Why do you want to use regular expressions to parse HTML when there are
    APIs for that like SgmlReader
    <URL:http://www.gotdotnet.c om/Community/UserSamples/Details.aspx?Sa mpleGuid=B90FDD CE-E60D-43F8-A5C4-C3BD760564BC>


    --

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

    Comment

    • Matteo Migliore

      #3
      Re: Retrieve tag A from html

      Why do you want to use regular expressions to parse HTML when there
      are APIs for that like SgmlReader
      Thanks! I see SqmlReader but for my problem is too much
      and I prefer to use .NET classes and RegEx.

      I downloaded the project but i don't like it very much :-).

      Thx! ;-)
      Matteo Migliore.

      Comment

      • Ignacio Machin \( .NET/ C# MVP \)

        #4
        Re: Retrieve tag A from html

        Hi,

        All you have to do is get the text from "<a" and up to "</a>"

        "Matteo Migliore" <matteo.miglior e.cut@gmail.com wrote in message
        news:OqLJWa2BIH A.3916@TK2MSFTN GP02.phx.gbl...
        Hi.
        >
        I need a regular expression to extract all tag A from HTML
        code. I need the href and text as two disting objects.
        >
        Suggestions?
        >
        Thx! ;-)
        Matteo Migliore.

        Comment

        • Jesse Houwing

          #5
          Re: Retrieve tag A from html

          Hello Ignacio Machin ( .NET/ C# MVP )" machin TA laceupsolutions .com,
          Hi,
          >
          All you have to do is get the text from "<a" and up to "</a>"
          >
          "Matteo Migliore" <matteo.miglior e.cut@gmail.com wrote in message
          news:OqLJWa2BIH A.3916@TK2MSFTN GP02.phx.gbl...
          >
          >Hi.
          >>
          >I need a regular expression to extract all tag A from HTML code. I
          >need the href and text as two disting objects.
          >>
          >Suggestions?
          >>
          >Thx! ;-)
          >Matteo Migliore.
          Which would come down to something like this:

          <a[^>]+href\s*=\s*"(? <href>[^"]+)"[^>]*>(?<text>(?:(? !</a).)*)

          It would save the href to a group named href and the text to a group named
          text.

          --
          Jesse Houwing
          jesse.houwing at sogeti.nl


          Comment

          Working...