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> > [email protected]<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 [email protected] (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:[email protected]">[email protected]</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:[email protected]">[email protected]</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 -- 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 [email protected] To unsubscribe from this group, send email to [email protected] 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 "[email protected]" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
