Converting email and web addresses to hyperlinks...

1,579 views
Skip to first unread message

Bo

unread,
May 17, 2011, 4:38:23 PM5/17/11
to BBEdit Talk
How does one convert email and web addresses to hyperlinks using
BBEdit.

Thanks in advance.

Alex Satrapa

unread,
May 17, 2011, 6:35:42 PM5/17/11
to bbe...@googlegroups.com
On 18 May 2011, at 06:38, Bo wrote:

> How does one convert email and web addresses to hyperlinks using
> BBEdit.

What sort of input are you expecting? Just plain text, HTML, something else?

If it's plain text, there's an interesting URL for matching an email address:
http://daringfireball.net/2009/11/liberal_regex_for_matching_urls

There is a useful resource for regular expressions over here:
http://regexlib.com/REDetails.aspx?regexp_id=501

(the one I've linked to directly is for matching URIs)

The next bit is using BBEdit Find & Replace with grep to do the legwork :)

Hope this helps!
Alex

Miraz Jordan

unread,
May 17, 2011, 7:14:32 PM5/17/11
to bbe...@googlegroups.com
[This is my second try at posting - apologies if you see it twice]

On Wed, May 18, 2011 at 08:38, Bo <bvhp...@gmail.com> wrote:
> How does one convert email and web addresses to hyperlinks using
> BBEdit.
>

I do it with the following Applescript. Caution: I'm not a scripting
expert. The script has worked well for me for several years, but you
should always check its output in case it does odd things for you.


================
-- This script turns selected text into a link.
-- Select text like www.google.com or http://www.google.com
-- or an email address like m...@example.com
-- and then run the script.
-- by Miraz Jordan, http://knowit.co.nz

tell application "BBEdit"


       make new text document with properties {contents:selection} at
text window 1
       tell front window

               -- set the static bits of code
               set h_ref to "<a href=\"http://"
               set last_bracket to "\">"
               set close_tag to "</a>"
               set mail_to to "mailto:"

               --   now we build the link
               -- delete any superfluous angle brackets
               replace "<" using ""

               replace ">" using ""


               select text 1
               set selection to h_ref & selection & last_bracket &
selection & close_tag

               -- clean up

               -- lose a trailing slash on the link text
               replace "/</a>" using "</a>"
               -- delete an http:// on link text
               replace ">http://" using ">"


               -- add an http:// to the link if necessary
               replace "href=\"www" using "href=\"http://www"
               -- add a mailto: to the link if necessary
               replace "href=\"(.+)@" using "href=\"mailto:\\1@" options {search
mode:grep, starting at top:true, wrap around:false, backwards:false,
case sensitive:false, match words:false, extend selection:false}

               -- tidy
               replace " </a>" using "</a>" options {search
mode:literal, starting
at top:true, wrap around:false, backwards:false, case sensitive:false,
match words:false, extend selection:false}

               replace "href=\"http://http://" using "href=\"http://"
               replace "href=\"mailto:http://" using "href=\"mailto:"

               -- return the URL to the old window
               set the_url to text 1
               close active document saving no
               set selection to the_url

               select insertion point after selection

               say "Here's your link."


       end tell


end tell
================


Cheers,

Miraz

--
MacTip: Project your iPad2 - http://mactips.info/2011/05/project-your-ipad2

KnowIT: Get some send some: try out torrents -
http://knowit.co.nz/2011/05/get-some-send-some-try-out-torrents

Bucky Junior

unread,
May 17, 2011, 8:10:49 PM5/17/11
to bbe...@googlegroups.com

Or are you looking for something even simpler?

email address: bbe...@googlegroups.com
email address as hyperlink: <a href="mailto:bbe...@googlegroups.com">mail bbedit group</a>

web address: http://groups.google.com/group/bbedit
web address as hyperlink: <a href="http://groups.google.com/group/bbedit">BBEdit Google Group</a>

If that answers your question in a way you were thinking, you may find these pages at W3C helpful. <http://www.w3schools.com/html/DEFAULT.asp>

bucky

Bo von Hohenlohe

unread,
May 17, 2011, 6:48:51 PM5/17/11
to bbe...@googlegroups.com
Thanks for your note.

I update a schedule for a client every few weeks, I paste the text into DreamWeaver, then I have to slog through turning all the email and web addresses to hyperlinks manually, bit of a nightmare.

Here is a sample schedule http://www.robertburridge.com/Workshops/schedule_sample.html that is basic html, next step would be to make the email and web addresses active hyperlinks.

It would be very nice to automate the process with a BBEdit grep, or a command line directive, what ever. I must have spent four hours on Google to no avail. Found an application http://www.unmarked.com/textsoap/ that stated it would do the trick but don't want to download it.

Any assistance would be much appreciated.

Thanks in advance.

> --
> You received this message because you are subscribed to the
> "BBEdit Talk" discussion group on Google Groups.
> To post to this group, send email to bbe...@googlegroups.com
> To unsubscribe from this group, send email to
> bbedit+un...@googlegroups.com
> For more options, visit this group at
> <http://groups.google.com/group/bbedit?hl=en>
> If you have a feature request or would like to report a problem,
> please email "sup...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Bo von Hohenlohe
bvhp...@gmail.com

Doug McNutt

unread,
May 17, 2011, 9:17:43 PM5/17/11
to bbe...@googlegroups.com
At 15:48 -0700 5/17/11, Bo von Hohenlohe wrote:
>Here is a sample schedule http://www.robertburridge.com/Workshops/schedule_sample.html that is basic html, next step would be to make the email and web addresses active hyperlinks.

Untested and based on your sample. The regular expressions are bare minimums. bbedit can do global replacements with similar regular expressions but I typically find it better to work with the original file when I know a lot about it.

Your source has a bunch of <br> tags that will need some special attention that isn't here.

#!/usr/bin/perl
$PathToOriginal = "Workshops/schedule_sample.html";
$PathToReplacement = "Workshops/fixed_sample.html"
open INPUT, $PathToOriginal or die "Can't open $PathToOriginal\n";
open OUTPUT, ">$PathToReplacement" or die "Can't open $PathToReplacement\ for outpur\n";\
while (<INPUT>) # reads one line at a time
{
chomp; # removes the line end.
if (/(www.*)/)
{
$newline = "<a href= \" http://$1\"> $1 </a>\n";
print OUTPUT $newline;
next;
}
if (/(\S)@(\S)(*)/)
{
$newline = "<a href=\"mailto:$1@$2\"> $1@$2 </a> $3\n";
print OUTPUT $newline;
next;
}
print "$_\n"; # Just print the line if we haven't changed anything.
}


--

--> A fair tax is one that you pay but I don't <--

Alex Satrapa

unread,
May 17, 2011, 9:30:16 PM5/17/11
to bbe...@googlegroups.com
On 18/05/2011, at 08:48 , Bo von Hohenlohe wrote:

> Here is a sample schedule http://www.robertburridge.com/Workshops/schedule_sample.html that is basic html, next step would be to make the email and web addresses active hyperlinks.

Working with John Gruber's regex, I end up with something that looks like this:

Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
Replace: <a href="\1">\1</a>

Tick the box for "Grep" and "Wrap around", click "Replace All":

> October 8-12, 2012<BR>
> <B>Loosen Up with Aquamedia Painting</B><BR>
> Vancouver Island Art Workshops<BR>
> Nanaimo, British Columbia,Canada<BR>
> Contact Mary Stewart, 250-716-1440<BR>
> marys...@telus.net<BR>
> <a href="http://www.VancouverIslandArtWorkshops.com">http://www.VancouverIslandArtWorkshops.com</a><BR>
> <BR>
> November 2-4, 2012<BR>
> <B>Create Today with Wild Abandon - No Brushes!</B><BR>
> 3-day Workshop (Friday-Sunday)<BR>
> San Luis Obispo Museum of Art, San Luis Obispo, CA<BR>
> Contact off...@sloartcenter.org (805) 543-8562 ext. 14<BR>
> <a href="www.sloartcenter.org">www.sloartcenter.org</a><BR>
> <BR>


Then of course I realised that John Gruber's regex is for URL detection. D'oh! So off to regexlib.com to find an email regex:

^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$

This email regex is appropriated from http://regexlib.com/REDetails.aspx?regexp_id=88

So Find & Replace gets us this (note I've wrapped the entire expression in brackets and removed the ^ and $ since I'm trying to *detect* rather than *validate* email addresses):

Find: ((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4})))
Replace: <a href="email:\1">\1</a>

Tick the box for "Grep" and "Wrap around", click "Replace All":

> October 8-12, 2012<BR>
> <B>Loosen Up with Aquamedia Painting</B><BR>
> Vancouver Island Art Workshops<BR>
> Nanaimo, British Columbia,Canada<BR>
> Contact Mary Stewart, 250-716-1440<BR>
> <a href="email:marys...@telus.net">marys...@telus.net</a><BR>
> <a href="http://www.VancouverIslandArtWorkshops.com">http://www.VancouverIslandArtWorkshops.com</a><BR>
> <BR>
> November 2-4, 2012<BR>
> <B>Create Today with Wild Abandon - No Brushes!</B><BR>
> 3-day Workshop (Friday-Sunday)<BR>
> San Luis Obispo Museum of Art, San Luis Obispo, CA<BR>
> Contact <a href="email:off...@sloartcenter.org">off...@sloartcenter.org</a> (805) 543-8562 ext. 14<BR>
> <a href="www.sloartcenter.org">www.sloartcenter.org</a><BR>
> <BR>


As for automating this, if I have to start writing any kind of script at all I'll just do the whole thing in Perl (and use that Perl script as a filter in BBEdit). I'll leave it up to the AppleScript guys on the list to suggest a script that will automate this Find & Replace in BBEdit (searching the list archives might uncover something interesting).

You can get part way to automation by saving those Find/Replace dialog options - select "Save…" in the little "g" menu, to the left of the "Previous" button. I've saved them as "URL to HREF" and "Email to HREF" respectively. This reduces the process of replacing web sites and email addresses to:
- ⌘F (open the Find/Replace dialog)
- Select "URL to HREF" from "g" menu
- Click "Replace All"
- Select "Email to HREF" from "g" menu
- Click "Replace All"

Finally, remember that these regexes will only catch about 99% of the URLs. You'll still need to proof read the HTML page in a browser to make sure they worked properly!

Hope this helps
Alex

PS: If you're interested in learning how those regular expressions work and how to craft your own, I recommend Jeffrey E.F. Friedl, "Mastering Regular Expressions" - http://oreilly.com/catalog/9780596528126

Bo

unread,
May 17, 2011, 9:58:41 PM5/17/11
to BBEdit Talk
Getting close, thank you...

1) This:

Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]
\s]|/)))
Replace: <a href="\1">\1</a>

Rendered this: <a href="www.artworkshops.com">www.artworkshops.com</a>

How do we add the 'http://' in the <a href="www.artworkshops.com">
(not in the text part).

2) Then I tried the email script:

Find: ((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)
+)([a-zA-Z]{2,4})))
Replace: <a href="email:\1">\1</a>

It didn't work so I change the 'email' to 'mailto', works fine now.

Looking forward to your changes to the "URL to HREF", I am totally
unfamiliar with this end of thing but I will fool with it a bit to see
if I can make the "URL to HREF" script add the 'http://'.

Thank you very, very much!!


On May 17, 6:30 pm, Alex Satrapa <gr...@goldweb.com.au> wrote:
> On 18/05/2011, at 08:48 , Bo von Hohenlohe wrote:
>
> > Here is a sample schedulehttp://www.robertburridge.com/Workshops/schedule_sample.htmlthat is basic html, next step would be to make the email and web addresses active hyperlinks.
>
> Working with John Gruber's regex, I end up with something that looks like this:
>
> Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
> Replace: <a href="\1">\1</a>
>
> Tick the box for "Grep" and "Wrap around", click "Replace All":
>
> > October 8-12, 2012<BR>
> > <B>Loosen Up with Aquamedia Painting</B><BR>
> > Vancouver Island Art Workshops<BR>
> > Nanaimo, British Columbia,Canada<BR>
> > Contact Mary Stewart, 250-716-1440<BR>
> > marystew...@telus.net<BR>
> > <a href="http://www.VancouverIslandArtWorkshops.com">http://www.VancouverIslandArtWorkshops.com</a><BR>
> > <BR>
> > November 2-4, 2012<BR>
> > <B>Create Today with Wild Abandon - No Brushes!</B><BR>
> > 3-day Workshop (Friday-Sunday)<BR>
> > San Luis Obispo Museum of Art, San Luis Obispo, CA<BR>
> > Contact off...@sloartcenter.org (805) 543-8562 ext. 14<BR>
> > <a href="www.sloartcenter.org">www.sloartcenter.org</a><BR>
> > <BR>
>
> Then of course I realised that John Gruber's regex is for URL detection. D'oh! So off to regexlib.com to find an email regex:
>
> ^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4 }))$
>
> This email regex is appropriated fromhttp://regexlib.com/REDetails.aspx?regexp_id=88
>
> So Find & Replace gets us this (note I've wrapped the entire expression in brackets and removed the ^ and $ since I'm trying to *detect* rather than *validate* email addresses):
>
> Find: ((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z] {2,4})))
> Replace: <a href="email:\1">\1</a>
>
> Tick the box for "Grep" and "Wrap around", click "Replace All":
>
> > October 8-12, 2012<BR>
> > <B>Loosen Up with Aquamedia Painting</B><BR>
> > Vancouver Island Art Workshops<BR>
> > Nanaimo, British Columbia,Canada<BR>
> > Contact Mary Stewart, 250-716-1440<BR>
> > <a href="email:marystew...@telus.net">marystew...@telus.net</a><BR>

Bo

unread,
May 17, 2011, 10:28:39 PM5/17/11
to BBEdit Talk
What a huge blessing, thank you very my Alex!!!

"URL to HREF"
Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]
\s]|/)))
Replace: <a href="http://\1">\1</a>

"Email to HREF"
Find: ((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)
+)([a-zA-Z]{2,4})))
Replace: <a href="mailto:\1">\1</a>



On May 17, 6:30 pm, Alex Satrapa <gr...@goldweb.com.au> wrote:
> On 18/05/2011, at 08:48 , Bo von Hohenlohe wrote:
>
> > Here is a sample schedulehttp://www.robertburridge.com/Workshops/schedule_sample.htmlthat is basic html, next step would be to make the email and web addresses active hyperlinks.
>
> Working with John Gruber's regex, I end up with something that looks like this:
>
> Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
> Replace: <a href="\1">\1</a>
>
> Tick the box for "Grep" and "Wrap around", click "Replace All":
>
> > October 8-12, 2012<BR>
> > <B>Loosen Up with Aquamedia Painting</B><BR>
> > Vancouver Island Art Workshops<BR>
> > Nanaimo, British Columbia,Canada<BR>
> > Contact Mary Stewart, 250-716-1440<BR>
> > marystew...@telus.net<BR>
> > <a href="http://www.VancouverIslandArtWorkshops.com">http://www.VancouverIslandArtWorkshops.com</a><BR>
> > <BR>
> > November 2-4, 2012<BR>
> > <B>Create Today with Wild Abandon - No Brushes!</B><BR>
> > 3-day Workshop (Friday-Sunday)<BR>
> > San Luis Obispo Museum of Art, San Luis Obispo, CA<BR>
> > Contact off...@sloartcenter.org (805) 543-8562 ext. 14<BR>
> > <a href="www.sloartcenter.org">www.sloartcenter.org</a><BR>
> > <BR>
>
> Then of course I realised that John Gruber's regex is for URL detection. D'oh! So off to regexlib.com to find an email regex:
>
> ^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4 }))$
>
> This email regex is appropriated fromhttp://regexlib.com/REDetails.aspx?regexp_id=88
>
> So Find & Replace gets us this (note I've wrapped the entire expression in brackets and removed the ^ and $ since I'm trying to *detect* rather than *validate* email addresses):
>
> Find: ((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z] {2,4})))
> Replace: <a href="email:\1">\1</a>
>
> Tick the box for "Grep" and "Wrap around", click "Replace All":
>
> > October 8-12, 2012<BR>
> > <B>Loosen Up with Aquamedia Painting</B><BR>
> > Vancouver Island Art Workshops<BR>
> > Nanaimo, British Columbia,Canada<BR>
> > Contact Mary Stewart, 250-716-1440<BR>
> > <a href="email:marystew...@telus.net">marystew...@telus.net</a><BR>

Bo

unread,
May 17, 2011, 10:11:52 PM5/17/11
to BBEdit Talk
Fixed it <a href="http://\1">\1</a>, not bad for an amateur!!!





On May 17, 6:30 pm, Alex Satrapa <gr...@goldweb.com.au> wrote:
> On 18/05/2011, at 08:48 , Bo von Hohenlohe wrote:
>
> > Here is a sample schedulehttp://www.robertburridge.com/Workshops/schedule_sample.htmlthat is basic html, next step would be to make the email and web addresses active hyperlinks.
>
> Working with John Gruber's regex, I end up with something that looks like this:
>
> Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
> Replace: <a href="\1">\1</a>
>
> Tick the box for "Grep" and "Wrap around", click "Replace All":
>
> > October 8-12, 2012<BR>
> > <B>Loosen Up with Aquamedia Painting</B><BR>
> > Vancouver Island Art Workshops<BR>
> > Nanaimo, British Columbia,Canada<BR>
> > Contact Mary Stewart, 250-716-1440<BR>
> > marystew...@telus.net<BR>
> > <a href="http://www.VancouverIslandArtWorkshops.com">http://www.VancouverIslandArtWorkshops.com</a><BR>
> > <BR>
> > November 2-4, 2012<BR>
> > <B>Create Today with Wild Abandon - No Brushes!</B><BR>
> > 3-day Workshop (Friday-Sunday)<BR>
> > San Luis Obispo Museum of Art, San Luis Obispo, CA<BR>
> > Contact off...@sloartcenter.org (805) 543-8562 ext. 14<BR>
> > <a href="www.sloartcenter.org">www.sloartcenter.org</a><BR>
> > <BR>
>
> Then of course I realised that John Gruber's regex is for URL detection. D'oh! So off to regexlib.com to find an email regex:
>
> ^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4 }))$
>
> This email regex is appropriated fromhttp://regexlib.com/REDetails.aspx?regexp_id=88
>
> So Find & Replace gets us this (note I've wrapped the entire expression in brackets and removed the ^ and $ since I'm trying to *detect* rather than *validate* email addresses):
>
> Find: ((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z] {2,4})))
> Replace: <a href="email:\1">\1</a>
>
> Tick the box for "Grep" and "Wrap around", click "Replace All":
>
> > October 8-12, 2012<BR>
> > <B>Loosen Up with Aquamedia Painting</B><BR>
> > Vancouver Island Art Workshops<BR>
> > Nanaimo, British Columbia,Canada<BR>
> > Contact Mary Stewart, 250-716-1440<BR>
> > <a href="email:marystew...@telus.net">marystew...@telus.net</a><BR>

Bo

unread,
May 17, 2011, 10:57:14 PM5/17/11
to BBEdit Talk
Thanks for all your replies and comments!!!

The solution Alex Satrapa came up with works perfectly!!

Converting email and web addresses to hyperlinks using BBEdit...

"URL to HREF"
Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]
\s]|/)))
Replace: <a href="http://\1">\1</a>
Replace: <a href="http://\1" target="_blank">\1</a> (add
target="_blank")

"Email to HREF"
Find: ((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)
+)([a-zA-Z]{2,4})))
Replace: <a href="mailto:\1">\1</a>

Alex Satrapa

unread,
May 18, 2011, 12:04:47 AM5/18/11
to bbe...@googlegroups.com
Apologies to the BBEdit list members, this conversation is getting a little noisy and only borderline relevant to BBEdit. For what it's worth, I regularly use BBEdit to build and test regular expressions, since it's much easier to try a Search/Replace and "undo" it in BBEdit, than it is to edit, save and rerun a Perl script as I'm testing it :)

On 18/05/2011, at 12:57 , Bo wrote:

> "URL to HREF"
> Find: \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]
> \s]|/)))
> Replace: <a href="http://\1">\1</a>
> Replace: <a href="http://\1" target="_blank">\1</a> (add
> target="_blank")

You'll be better off without the 'http://' bit there, since the regex will match URLs that already start with a scheme. Thus you'll end up with "http://http://www.VancourverIslandArtWorkshop.com" as a URL in one of the items down towards the bottom of the sample report that you showed us. This correction is potentially job-saving, so I'm posting to the list.

To add the "http://" in there, I'd suggest a third regex, which you will need to run *last*:

Find: href\s*=\s*"(?![[:alnum:]/]*?:)
Replace: href="http://

Tick the box for "Grep" and "Wrap around".

This will add the "http://" bit to only those HREF URIs which do not have something that looks like a scheme specifier in front:
- href="mailto:j...@example.com" will not be touched
- href="http://foo.example.com" will not be touched
- href="foo.example.com" will become href="http://foo.example.com"
- foo.example.com by itself will not be touched

Alex

PS: I made a boo-boo. The correct scheme for emails is "mailto" not "email". That's the second "Email to HREF" regex I posted earlier.

Christopher Stone

unread,
Mar 21, 2013, 8:41:19 PM3/21/13
to bbe...@googlegroups.com
On Mar 21, 2013, at 15:20, Grant Grueninger <grant.gr...@gmail.com> wrote:
my $input = '';
while (<>) {
$input .= $_;
}
______________________________________________________________________

Hey Grant,

If you're going to slurp the input into a variable, you might as well do it the easy way:

-------------------------------------------------------------------------------------------

#! /usr/bin/env perl -0777 -nw
use strict;

s%\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))%<a href="$1">$1</a>%g;
s%((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4})))%<a href="mailto:$1">$1</a>%g;
s%href\s*=\s*"(?![[:alnum:]/]*?:)%href="http://%g;
print;

-------------------------------------------------------------------------------------------

If you're going to process line-by-line, you might as well do it the easy way:

-------------------------------------------------------------------------------------------

#! /usr/bin/env perl -w
use strict;

while (<>) {
s%\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))%<a href="$1">$1</a>%g;
s%((?:[\w\-\.]+)@(?:(\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4})))%<a href="mailto:$1">$1</a>%g;
s%href\s*=\s*"(?![[:alnum:]/]*?:)%href="http://%g;
print;
}

-------------------------------------------------------------------------------------------

In both cases the default variable ($_) is implied.

It's also nice to have consistent pattern delimiters if possible.

--
Best Regards,
Chris

Reply all
Reply to author
Forward
0 new messages