Solved

Extracting links from a string

Posted on 2002-06-30
2
146 Views
Last Modified: 2010-03-05
Ok theres regular expression that will extract links from a url or file such as
#!/usr/bin/perl -n -00
while ( /<\s*A\s+HREF\s*=\s*(["'])(.*?)\1.*?>/gi ) {
         print "$2\n";
}

I need a sub routine that I can pass a string and extract the links from a string. Is there anyway I can adapt Tom Christiansen work, or does anyone know how I can do this?
Cheers
Ryan
0
Comment
Question by:NoFrills
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7120858
sub extractlinks{
    local $_ = shift;
    my @links = ();
    while ( /<\s*A\s+HREF\s*=\s*(["'])(.*?)\1.*?>/gi ) {
        push @links,$2;
    }
    return @links;
0
 
LVL 3

Expert Comment

by:DVB
ID: 7134631
use HTML::Parse;
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now