Issue 67* March 13 2009

Use RegEx to reformat dates
Here's a couple of handy routines to massage dates from Web server logs into a format that Revolution can easily understand

by Bill Marriott

from the Use-Revolution mailing list

Web server logs are a natural for processing with Revolution. You can use the FTP functions to download the logs from the server, and then employ Revolution's powerful chunk expressions to slice the data up and analyze it. By analyzing server logs, you can discover dead links, find out who is visiting your web site, see which search engines are indexing it, learn what browsers and operating systems are most popular with your readers, which pages are viewed most often, and much more.

There's one hitch though. One of the most popular server technologies is Apache, and their log files produce dates in a rather unusual format. For example:

10/Oct/2000:13:55:36 -0700

Which is different from Revolutions' "internet date"

Fri, 13 Mar 2009 12:20:48 -0800

This doesn't match up to any of the built-in formats supported by Revolution's "convert" function. So, how to transform this part of the log entry to a format that Revolution can use?

Method One: Chunk Expressions
Longtime HyperCard users will probably employ a technique like this:

function apacheDate1 d   
   replace slash with space in d   
   put space into char offset(":",d) of d   
   put lineoffset(word 2 of d, the monthnames)
   & slash & word 1 of d & \
              slash & word 3 of d into m   
   convert m to abbreviated date   
   return word 1 of m && d 
end apacheDate1 

Method Two: Regular Expressions
This is a useful approach because we learn one of the special abilities of the matchText function, which can drop values into a list of variables in one go:

function apacheDate2 d   
   get matchText(d,"(.*?)/(.*?)/(.*?):(.*?)$",tDay,tMonth,tYear,tRest)  
   convert (tMonth && tDay && tYear) to abbr date   
   return (item 1 of it) & "," && tDay && tMonth && tYear && tRest
end apacheDate2 

 

 

 

About the Thread

Thanks to Revolution users Jim Ault, Robert Brenstein, Richard Gaskin, Ken Ray, and Mark Smith who contributed to this discussion.

 

Main Menu

What's New

Merchandise