On Sat, Feb 21, 2004 at 07:44:15PM +0100, Anthony Vanelverdinghe ([EMAIL PROTECTED])
wrote:
> Hi
>
> 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);
> }
>
I'm sure others will do a better job but this seems to do the
trick. This is assuming the quotes will always be there. -
------------------------------------------------------------
#!/usr/bin/perl
use warnings;
use strict;
while (<DATA>) {
$_ =~ /^\s*<DT><A HREF="(.+)">(.+)<\/A>$/i;
print "$1 $2\n";
}
__DATA__
<DT><A HREF="http://urltonowhere1.com/">To Nowhere1</A>
<DT><a href="http://urltonowhere2.com/">To Nowhere2</a>
<DT><A HREF="http://urltonowhere3.com/">To Nowhere3</A>
------------------------------------------------------------
Output -
[slock:~/scratch/beginners/regex]$ ./url.pl
1,1 All
http://urltonowhere1.com/ To Nowhere1
http://urltonowhere2.com/ To Nowhere2
http://urltonowhere3.com/ To Nowhere3
hth,
Kent
--
"Efficiency is intelligent laziness."
-David Dunham
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>