Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Extracting a date..

From: peoyli:algonet:se at: 12-May-2001 22:35

Hi, Thanks for the solutions to this problem. I finally decided to use and extend Ingo's solution (but I already had a version that works based on the Scott's example) because it didn't accept 'May 1a 20ab' as the date, and because I already had need for a block with the abbreviated month names. Thanks to Joel for the explanation why my initial attempts failed, and to Graham for the first attempt to solve the problem (which should have succeeded with a little more experimenting). Changes: made into a function which returns a numerical date format of yy(yy)-mm-dd, or 'none' if no date in file. --- extract-date: func [ {Extract the first occurrance of a date [mmm-d(d)-yy(yy)] in a string} text [string!] {The string to extract the date from} /local space digit month day year date-rule m d y ][ space: [ thru " " ] digit: charset [#"0" - #"9"] month: [ "jan" | "feb" | "mar" | "apr" | "may" | "jun" | "jul" | "aug" | "sep" | "oct" | "nov" | "dec" ] day: [ 1 2 digit ] year: [ 2 4 digit ] date-rule: [ copy m month space copy d day space copy y year ] either parse/all fdata [ any [ date-rule to end | thru " " ]] [ m: to-string (index? find month m) + 1 / 2 if 2 > length? m [insert m "0"] if 2 > length? d [insert d "0"] rejoin [y "-" m "-" d] ; date: to-date rejoin [y "-" m "-" d] ][ none ] ] --- /PeO