URL and email regex

Ken Ray kray at sonsothunder.com
Tue Sep 28 10:51:20 EDT 2004


On 9/28/04 6:08 AM, "Jesse Sng" <jsng at wayoflife.org> wrote:

> Hi,
> 
> Does anyone have a handy regex for detecting and selecting a chunk of
> text that is a to be made into a URL or an email address?

Jesse, here's one for an email address (*really* watch for line breaks - I
put in hard returns and indents so it formats properly and is legible, but
you'll have to take them out):

function isEmail pWhat
  put matchText(pWhat,"^[A-z0-9_\-\.]+[@][A-z0-9_\-]+
     ([.][A-z0-9_\-]+)+[A-z]$") into tNotIP
  put matchText(pWhat,"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})
      \.(\d{1,3})$") into tIsIP
  return (tIsIP or tNotIP)
  -- supports:
  --   periods in user address (ken.ray at test.com)
  --   multiple subdomains (kenray at test.co.uk)
  --   new domains with more than 2 characters (.info, .museum, etc.)
  --   IP addresses
end isEmail

HTH,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list