Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

using Email::Find and URI::Find

by gav^ (Curate)
on Mar 21, 2002 at 22:28 UTC ( #153447=note: print w/ replies, xml ) Need Help??


in reply to Look-behind regex to

If you look at Email::Find and URI::Find you'll find 2 modules that do the job, eg

use Email::Find; my $finder = Email::Find->new( sub { my($email, $orig_email) = @_; my($address) = $email->format; return qq|<a href="mailto:$address">$orig_email</a>|; }, ); $finder->find(\$text);
and
use URI::Find; find_uris($text, sub { my($uri, $orig_uri) = @_; return qq|<a href="$uri">$orig_uri</a>|; });
Examples pulled from the docs. You might also find HTML::FromText handy for formatting text (and converting URLs etc).

Hope this helps.

gav^


Comment on using Email::Find and URI::Find
Select or Download Code
Replies are listed 'Best First'.
Re: using Email::Find and URI::Find
by Kozz (Friar) on Mar 21, 2002 at 22:48 UTC
    Thank you for the tips. The URI Unfortunately, Email::Find chokes on those complex URIs containing usernames in those cases. Example output from that module:
    An email address is <a href="mailto:foo-master@bar.com">foo-master@b +ar.com</a>, but this http:<a href="mailto://foo@bar.com">//foo@bar.com</a>/ and this ftp://foo:<a href="mailto:baz@bar.com">baz@bar.com</a>/ are not emails.
    I wonder if one would have to copy some Email::Find code and modify it with a negative zero-width look-behind for (ht|f)tp:// ?

    (p.s. my apologies for the unfinished node title! I got caught up with the code.)

      I wonder if one would have to copy some Email::Find code and modify it with a negative zero-width look-behind for (ht|f)tp:// ?

      It's even easier then that.

      The docs for Email::Find have a section entitled "SUBCLASSING" that explains how you can make your own version with a different regex, or validation function. You can create a basic subclass that just defienes a new regex (with spaces before and after, and or enclosed in "<...>" -- whatever you want. "

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://153447]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-07-29 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls