Script Library: 1181 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: chrisrg

Documentation for: extract-urls.r


Extract URLs

Separates URLs from the body of plain text. Inspired by John Gruber (except REBOL doesn't do Regex):

A Liberal, Accurate Regex Pattern for Matching URLs

This function returns a block containing strings and urls.

1. Example Usage:

 do %extract-urls.r

 sanitize: func [str][
     foreach [fr to][
         "&" "&" "<" "<" "^"" """
     ][
         replace/all str fr to
     ]
 ]

 link-up: func [str][
     foreach part extract-urls str [
         append "" either url? part [
             rejoin [{<a href="} part: sanitize form part {">} part {</a>}]
         ][
             sanitize part
         ]
     ]
 ]

This will take a plain text string and replace URLs with HTML link tags.