Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Attempting to get all my http and https links. This gets a hit but was hoping to fine tune this better. Please provide a better reg expression if possible?
if($line =~ /(https?\:.*")/)
The above reg expression should give me this, but it doesn always work because sometimes it fetches the whole line with other end quotes.
<a href="http://www.mylinke.com">Link</a>
I need output like this:
http://www.mylinke.com

Thanks.

Replies are listed 'Best First'.
Re: Link reg expression
by artist (Parson) on Jun 19, 2003 at 18:10 UTC
Re: Link reg expression
by CukiMnstr (Deacon) on Jun 19, 2003 at 18:09 UTC
    it fetchs other end quotes because you are asking it to with .*. If you change your code to:
    if ( $line =~ m/(https?:[^"]+")/ )
    it should work. Also, you could try the non-greedy form:
    if ( $line =~ m/(https?:.+?")/ )
    check perlre for more on the non-greedy quantifiers, and read this post by Ovid on the dangers of .*.

    hope this helps,

    update: you should be using a module specifically designed to deal with links in html documents for this, anyway.