Anthony Vanelverdinghe wrote:
>
> I want to save the name and the URL of a html hyperlink in an array
> (@bookmarks).
>
> The problem is that the quotes aren't recognized, so it doesn't save only
> the URL;
> but also the other attributes of <A...>
> How can i make sure only the URL between the quotes is saved?
>
> if (/^\s*<DT><A HREF="(.+)".*>(.+)<\/A>\s*$/i){
>          push (@bookmarks,$2,$1);
> }

Hi Anthony.

Regexes aren't good for parsing HTML. But if your requirements
are very simple, then you could get away with using 'non-greedy'
quantifiers in your regex. Try this:

  if ( m[<DT><A HREF="(.+?)".*?>(.+?)</A>]i ){
    push (@bookmarks,$2,$1);
  }

but don't forget that this will stop working if the detail of
your HTML changes.

HTH,

Rob




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to