Monday, December 22, 2014

#1 2012-02-12 10:52:32 am

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4638

Is there a better RegEx for this?

To convert dates in text that often occur in variable formats to a uniform standard, I found the following pair of regular expressions to do it and wrote the script below from them using Satimage Text Tools. Is there a better way than the two-step process here?

Applescript:


(*
Regular Expressions by James Sehrier on Keyboard Maestro list that I have adjusted from that format to Satimage regexp AppleScript format.
*)


set myDates to {"3/30/10", "9/11/2012", "1/1/2000"}

--> get dates to date that is (0)mm/(0)dd/(yy)yy format
set regEx_1 to "(\\d+)(?:/)(\\d+)(?:/)(\\d+)"
set Replace_1 to "0\\1/0\\2/\\3"

--> then fix for mm/dd/yy format
set regEx_2 to "(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d$)"
set Replace_2 to "\\1\\2\\3"

set newDates to {}

repeat with oneDate in myDates
   set T1 to change regEx_1 into Replace_1 in oneDate with regexp
   set T2 to change regEx_2 into Replace_2 in T1 with regexp
   set end of newDates to T2
end repeat

--> newDates = {"03/30/10", "09/11/12", "01/01/00"}


iMac & MBP both running OS X 10.9.1

Offline

 

#2 2012-02-12 11:33:57 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

Hi, Adam.

I don't know about reducing the number of steps, but it's possible to do them all with one 'change' command:

Applescript:


(*
Regular Expressions by James Sehrier on Keyboard Maestro list that I have adjusted from that format to Satimage regexp AppleScript format.
*)


set myDates to {"3/30/10", "9/11/2012", "1/1/2000"}

--> get dates to date that is (0)mm/(0)dd/(yy)yy format
set regEx_1 to "(\\d+)(?:/)(\\d+)(?:/)(\\d+)"
set Replace_1 to "0\\1/0\\2/\\3"

--> then fix for mm/dd/yy format
set regEx_2 to "(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d$)"
set Replace_2 to "\\1\\2\\3"

set newDates to {}

repeat with oneDate in myDates
   set end of newDates to (change {regEx_1, regEx_2} into {Replace_1, Replace_2} in oneDate with regexp)
end repeat

newDates --> {"03/30/10", "09/11/12", "01/01/00"}


NG

Offline

 

#3 2012-02-12 11:55:20 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

How to edit this script to keep four digits years which, from my point of view, is the best format ?

Yvan KOENIG (VALLAURIS, France) dimanche 12 février 2012 18:55:04

Offline

 

#4 2012-02-12 12:53:58 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4638

Re: Is there a better RegEx for this?

@Nigel;

My version was simply nested:

Applescript:

repeat with oneDate in myDates
   set end of newDates to change regEx_2 into Replace_2 in (change regEx_1 into Replace_1 in oneDate with regexp) with regexp
end repeat

Yours is much cleaner -- I didn't know Text Tools would accommodate a list input.

@Yvan;

I'm a newbie at regex so I don't know how to dot that without a lot of struggling. I will try.


iMac & MBP both running OS X 10.9.1

Offline

 

#5 2012-02-12 02:09:12 pm

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

Yvan Koenig wrote:

How to edit this script to keep four digits years which, from my point of view, is the best format ?

A simple way to patch it would be to make the value of Replace_2 "\\1\\220\\3". There are undoubtedly better ways in terms of the overall process.

Last edited by Nigel Garvey (2012-02-12 02:09:34 pm)


NG

Offline

 

#6 2012-02-13 03:48:01 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

Thank you.

Now, I will try to decipher that.

Yvan KOENIG (VALLAURIS, France) lundi 13 février 2012 10:47:52

Offline

 

#7 2012-02-13 08:51:59 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

Yvan Koenig wrote:

Now, I will try to decipher that.

It's the regex equivalent of a number of 'text -2 thru -1 of ("0" & myNumber)' operations.  smile

Applescript:

-- This is just to explain the regex. I doesn't perform it.

set myDates to {"3/30/10", "9/11/2012", "1/1/2000"}

set regEx_1 to "(\\d+)(?:/)(\\d+)(?:/)(\\d+)" -- (Remember digits)(forget "/")(remember digits)(forget "/")(remember digits)
set Replace_1 to "0\\1/0\\2/\\3" -- Replace with "0(memory 1)/0(memory 2)/(memory 3)"
--> "03/030/10" or "09/011/2012" or "01/01/2000"

-- Then:
set regEx_2 to "(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d$)" -- (Forget digits)(but remember the two before "/" and the "/" itself)(forget digits)(but remember the two before "/" and the "/" itself)(forget digits)(but remember the two before the end of the string)
set Replace_2 to "\\1\\220\\3" -- Replace with "(memory 1)(memory 2)20(memory 3)"
--> "03/30/2010" or "09/11/2012" or "01/01/2000"

I'm only just learning this stuff myself!


NG

Offline

 

#8 2012-02-13 09:29:59 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

Thanks Nigel

Yvan KOENIG (VALLAURIS, France) lundi 13 février 2012 15:56:03

Offline

 

#9 2012-03-31 03:12:04 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

Hello

I'm glad because I found a way to get a better result.

The existing code replaced year 1943 by year 2043.
It was really annoying because I was born in 1943 wink

So I used an edited code.

Applescript:


(*
Regular Expressions by James Sehrier on Keyboard Maestro list that I have adjusted from that format to Satimage regexp AppleScript format.
*)


set myDates to {"3/30/10", "9/11/2012", "1/1/00", "31/12/43", "31/12/1943"}

--> get dates to date that is (0)mm/(0)dd/(yy)yy format
set regEx_1 to "(\\d+)(?:/)(\\d+)(?:/)(\\d+)"
set Replace_1 to "0\\1/0\\2/20\\3"

--> then fix for mm/dd/yy format
set regEx_2 to "(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d\\d\\d$)"
set Replace_2 to "\\1\\2\\3"

set newDates to {}

repeat with oneDate in myDates
   (change regEx_1 into Replace_1 in oneDate with regexp)
   (change regEx_2 into Replace_2 in result with regexp)
   set end of newDates to result
   --set end of newDates to (change {regEx_1, regEx_2} into {Replace_1, Replace_2} in oneDate with regexp)
end repeat

newDates --> {"03/30/2010", "09/11/2012", "01/01/2000", "31/12/2043", "31/12/1943"}

Yvan KOENIG (VALLAURIS, France) samedi 31 mars 2012 22:11:49

Last edited by Yvan Koenig (2012-03-31 03:13:25 pm)

Offline

 

#10 2012-03-31 05:11:22 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4638

Re: Is there a better RegEx for this?

Clever, Ivan;

I too have seen that Keyboard Maestro macro but didn't think to translate it.


iMac & MBP both running OS X 10.9.1

Offline

 

#11 2012-04-01 02:51:08 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

Hello Adam

In fact, I started from your script or maybe from Nigel's one wink

Now I will try to convert it for Shane STANLEY's ASObjC Runner because I'm not sure that we will be able to use OSAXens when SandBoxing will be widely spread.

Yvan KOENIG (VALLAURIS, France) dimanche 1 avril 2012 09:49:04

Offline

 

#12 2012-04-01 03:27:46 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

Hi, I got it.

Applescript:


(*
Regular Expressions by James Sehrier on Keyboard Maestro list that I have adjusted from that format to Shane Stanley's ASObjC.app.
*)


set myDates to {"3/30/10", "9/11/2012", "1/1/00", "31/12/1943", "31/12/43"}

--> get dates to date that is (0)mm/(0)dd/(20)(yy)yy format
set regEx_1 to "(\\d+)(?:/)(\\d+)(?:/)(\\d+)"
set Replace_1 to "0$1/0$2/20$3"

--> then fix for mm/dd/yyyy format
set regEx_2 to "(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d/)(?:\\d*)(\\d\\d\\d\\d$)"
set Replace_2 to "$1$2$3"

tell application "ASObjC Runner"
   (*
   look for regEx_1 in myDates replacing with Replace_1
   --> {"03/030/2010", "09/011/202012", "01/01/2000", "031/012/201943", "031/012/2043"}
   look for regEx_2 in result replacing with Replace_2
   --> {"03/30/2010", "09/11/2012", "01/01/2000", "31/12/1943", "31/12/2043"}
   set newDates to result
   *)

   set newDates to look for regEx_2 in (look for regEx_1 in myDates replacing with Replace_1) replacing with Replace_2
end tell
newDates --> {"03/30/2010", "09/11/2012", "01/01/2000", "31/12/1943", "31/12/2043"}

As you may see, like the regex one, it behaves the same for dd/mm/(yy)yy and mm/dd/(yy)yy.

Yvan KOENIG (VALLAURIS, France) dimanche 1 avril 2012 10:27:00

Last edited by Yvan Koenig (2012-04-01 03:31:18 am)

Offline

 

#13 2012-04-01 08:27:51 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

Nice, Yvan.  smile

Just for good measure, here's a shell-script version. I've included an extra stage to interpret single-digit years too, as in "2/2/2".

Applescript:


(*
Regular Expressions by James Sehrier on Keyboard Maestro list that Adam Bell has adjusted from that format to Satimage regexp AppleScript format. Modified by Yvan Koenig to return four-digit years. Adapted thence for sed by NG.
*)


set myDates to {"3/30/10", "9/11/2012", "1/1/00", "2/2/2", "31/12/43", "31/12/1943", "9/3/1949", "7/7/7"}

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set myDates to myDates as text
set AppleScript's text item delimiters to astid

--> get dates to date that is (0)mm/(0)dd/(yy)yy format
set regEx_1 to "([0-9]+/)([0-9]+/)([0-9])"
set Replace_1 to "0\\10\\220\\3"

-- Insert an extra "0" into any year which begins with "20" and only has 3 digits.
set regEx_1a to "/20([0-9]([^0-9]\\|$))"
set Replace_1a to "/200\\1"

--> then fix for mm/dd/yy format
set regEx_2 to "[0-9]*([0-9]{2}/)[0-9]*([0-9]{2}/)[0-9]*([0-9]{4})"
set Replace_2 to "\\1\\2\\3"

set newDates to paragraphs of (do shell script ("echo " & myDates & " | sed -Ee 's|" & regEx_1 & "|" & Replace_1 & "|g' -e 's|" & regEx_1a & "|" & Replace_1a & "|g' -e 's|" & regEx_2 & "|" & Replace_2 & "|g'"))
--> {"03/30/2010", "09/11/2012", "01/01/2000", "02/02/2002", "31/12/2043", "31/12/1943", "09/03/1949", "07/07/2007"}

Last edited by Nigel Garvey (2012-04-01 10:38:12 am)


NG

Offline

 

#14 2012-04-01 09:36:06 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

Hi Nigel

The first conversion was not mine. It was an Adam Bell's one smile

Of course, as your version requires no third party tool, it's my preferred one.

Yvan KOENIG (VALLAURIS, France) dimanche 1 avril 2012 16:35:57

Last edited by Yvan Koenig (2012-04-01 09:37:15 am)

Offline

 

#15 2012-04-01 10:43:41 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

Yvan Koenig wrote:

The first conversion was not mine. It was an Adam Bell's one smile

OK. I've redistributed my praise at the top of the script. I think it's right now.  wink


NG

Offline

 

#16 2012-04-01 11:30:15 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 1601

Re: Is there a better RegEx for this?

Thanks.

In French we say : "Il faut rendre à César ce qui est à César".

In English it may be :
"Render therefore unto Caesar the things which are Caesar's"

or

"give credit where credit is due"

Better don't hurt the forum's admin wink

Yvan KOENIG (VALLAURIS, France) dimanche 1 avril 2012 18:29:52

Last edited by Yvan Koenig (2012-04-01 11:31:07 am)

Offline

 

#17 2012-04-01 12:14:31 pm

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

Yvan Koenig wrote:

"Render therefore unto Caesar the things which are Caesar's"

or

"give credit where credit is due"

Better don't hurt the forum's admin wink

Adamus Bellicosus Maximus Caesar — Imperator (sub Raio Barbero) Fororum MacScripteri!

One can't help but tremble a little….  hmm


NG

Offline

 

#18 2012-04-01 04:42:28 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4638

Re: Is there a better RegEx for this?

Get real, guys big_smile


iMac & MBP both running OS X 10.9.1

Offline

 

#19 2012-04-01 05:32:45 pm

rickoberndorf
Member
Registered: 2005-11-02
Posts: 7

Re: Is there a better RegEx for this?

Since you're using Satimage anyway, how about using the strftime function as follows?

Applescript:


set myDates to {"3/30/10", "9/11/2012", "1/1/2000"}

set newDates to {}
repeat with oneDate in myDates
   set end of newDates to strftime date oneDate into "%m/%d/%y"
end repeat

Offline

 

#20 2012-04-02 02:45:09 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

rickoberndorf wrote:

Since you're using Satimage anyway, how about using the strftime function as follows?

Hi.

Thanks for the suggestion, about which I myself didn't know. It has a slight restriction in that it only works where the user's short-date-order preference ("Formats" in the "Language & Text" preference pane) matches the dates in the list. Otherwise it errors on out-of-range numbers. (The "30" in the first date is out of range in my dd/mm/yyyy set-up.) However, this often won't be a problem. The Regex approach works with both dd/mm/yyyy and mm/dd/yyyy short dates, but not (obviously) with yyyy/mm/dd dates or (in the scripts above) with different separators.


NG

Offline

 

#21 2012-04-02 03:09:25 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

I wrote:

The Regex approach works with both dd/mm/yyyy and mm/dd/yyyy short dates, but not (obviously) with yyyy/mm/dd dates or (in the scripts above) with different separators.

OK. Here's a version that's more flexible about separators:

Applescript:

(*
Regular Expressions by James Sehrier on Keyboard Maestro list that Adam Bell has adjusted from that format to Satimage regexp AppleScript format. Modified by Yvan Koenig to return four-digit years. Adapted thence for sed by NG.
*)


set myDates to {"3/30/10", "9.11.2012", "1-1-00", "2:2:2", "31 12 43", "31_12_1943", "9a3b1949", "7c7d7"}

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set myDates to myDates as text
set AppleScript's text item delimiters to astid

--> get dates to date that is (0)mm/(0)dd/(yy)yy format
set regEx_1 to "([0-9]+[^0-9])([0-9]+[^0-9])([0-9]+)"
set Replace_1 to "0\\10\\220\\3"

-- Insert an extra "0" into any year which begins with "20" and only has 3 digits.
set regEx_1a to "([^0-9])20([0-9]([^0-9]\\|$))"
set Replace_1a to "\\1200\\2"

--> then fix for mm/dd/yy format
set regEx_2 to "[0-9]*([0-9]{2}[^0-9])[0-9]*([0-9]{2}[^0-9])[0-9]*([0-9]{4})"
set Replace_2 to "\\1\\2\\3"

set newDates to paragraphs of (do shell script ("echo " & myDates & " | sed -Ee 's|" & regEx_1 & "|" & Replace_1 & "|g' -e 's|" & regEx_1a & "|" & Replace_1a & "|g' -e 's|" & regEx_2 & "|" & Replace_2 & "|g'"))
--> {"03/30/2010", "09.11.2012", "01-01-2000", "02:02:2002", "31 12 2043", "31_12_1943", "09a03b1949", "07c07d2007"}


NG

Offline

 

#22 2012-04-02 12:08:56 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4638

Re: Is there a better RegEx for this?

Nigel's solution directly above neatly solves the approach I had taken. Unlike him, I'm hopeless so far with sed. As you can see, I just added a bit to fix the date order. A work in progress that will next incorporate Nigel's fix.

Applescript:


-- Nigel's version of RegExDates converted to handler with choice by acb

(*
Regular Expressions by James Sehrier on Keyboard Maestro list that Yvan Koenig has adjusted from that format to Satimage regexp AppleScript format. Adjusted thence for sed by NG.
*)


set myDates to {"3/30/10", "9/11/2012", "1/1/00", "2/2/2", "31/12/43", "31/12/1943", "9/3/1949", "7/7/7"}

NormalizeDates(myDates, "FS", ".") -- a list, type of presentation, delimiter preferred

to NormalizeDates(dateList, Dtype, delim) -- Dtypes: "FS" or "ddmmyyyy"
   -- replace the list variable with paragraphs of a single string for regex analysis
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to return
   set myDates to dateList as text
   set AppleScript's text item delimiters to astid
   
   --> get dates to date that is (0)mm/(0)dd/(yy)yy format
   set regEx_1 to "([0-9]+/)([0-9]+/)([0-9])"
   set Replace_1 to "0\\10\\220\\3"
   
   -- Insert an extra "0" into any year which begins with "20" and only has 3 digits.
   set regEx_1a to "/20([0-9]([^0-9]\\|$))"
   set Replace_1a to "/200\\1"
   
   --> then fix for mm/dd/yy format
   set regEx_2 to "[0-9]*([0-9]{2}/)[0-9]*([0-9]{2}/)[0-9]*([0-9]{4})"
   set Replace_2 to "\\1\\2\\3"
   
   set newDates to paragraphs of (do shell script ("echo " & myDates & " | sed -Ee 's|" & regEx_1 & "|" & Replace_1 & "|g' -e 's|" & regEx_1a & "|" & Replace_1a & "|g' -e 's|" & regEx_2 & "|" & Replace_2 & "|g'"))
   
   --> {"03/30/2010", "09/11/2012", "01/01/2000", "02/02/2002", "31/12/2043", "31/12/1943", "09/03/1949", "07/07/2007"}
   
   if Dtype is "FS" then
       -- reverse date order in newDates
       set yearFirst to {}
       repeat with oneDate in newDates
           set end of yearFirst to my ReverseDateOrder(oneDate, delim)
       end repeat
       set newDates to yearFirst
   end if
   return newDates
end NormalizeDates

to ReverseDateOrder(dateText, delim)
   set tid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to "/"
   set Rev to reverse of (text items of dateText)
   set AppleScript's text item delimiters to delim
   return Rev as text
   set AppleScript's text item delimiters to tid
end ReverseDateOrder


iMac & MBP both running OS X 10.9.1

Offline

 

#23 2012-04-03 05:29:18 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 3609

Re: Is there a better RegEx for this?

Hi, Adam. Ever more flexible!  smile

With a slight change to regEx_2, it's possible to achieve reversals and separator impositions by supplying an appropriate Replace_2:

Applescript:

(*
Regular Expressions by James Sehrier on Keyboard Maestro list that Adam Bell has adjusted from that format to Satimage regexp AppleScript format. Modified by Yvan Koenig to return four-digit years. Adapted thence for sed by NG. Converted to handler with choice by acb. Further fooled with by NG.
*)


to NormalizeDates(myDates, params)
   set {fs:fs, delim:delim} to (params & {fs:false, delim:missing value})
   
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to return
   set myDates to myDates as text
   set AppleScript's text item delimiters to astid
   
   --> get dates to date that is (0)mm/(0)dd/(yy)yy format
   set regEx_1 to "([0-9]+[^0-9])([0-9]+[^0-9])([0-9]+)"
   set Replace_1 to "0\\10\\220\\3"
   
   -- Insert an extra "0" into any year which begins with "20" and only has 3 digits.
   set regEx_1a to "([^0-9])20([0-9]([^0-9]\\|$))"
   set Replace_1a to "\\1200\\2"
   
   --> then fix for mm/dd/yyyy format and handle reversal and/or separator imposition as specified.
   set regEx_2 to "[0-9]*([0-9]{2})([^0-9])[0-9]*([0-9]{2})([^0-9])[0-9]*([0-9]{4})"
   if (delim is missing value) then -- Use existing separators.
       if (fs) then -- Reverse the element order.
           set Replace_2 to "\\5\\4\\3\\2\\1"
       else -- Maintain the element order.
           set Replace_2 to "\\1\\2\\3\\4\\5"
       end if
   else -- Use the parameter-specified separator.
       if (fs) then -- Reverse the element order.
           set Replace_2 to "\\5" & delim & "\\3" & delim & "\\1"
       else -- Maintain the element order.
           set Replace_2 to "\\1" & delim & "\\3" & delim & "\\5"
       end if
   end if
   
   set newDates to paragraphs of (do shell script ("echo " & myDates & " | sed -Ee 's|" & regEx_1 & "|" & Replace_1 & "|g' -e 's|" & regEx_1a & "|" & Replace_1a & "|g' -e 's|" & regEx_2 & "|" & Replace_2 & "|g'"))
end NormalizeDates

set myDates to {"3/30/10", "9.11.2012", "1-1-00", "2:2:2", "31 12 43", "31_12_1943", "9a3b1949", "7c7d7"}

NormalizeDates(myDates, {}) -- Defaults: same ddmmyyyy or mmddyyyy order, same separator(s).
--> {"03/30/2010", "09.11.2012", "01-01-2000", "02:02:2002", "31 12 2043", "31_12_1943", "09a03b1949", "07c07d2007"}
NormalizeDates(myDates, {fs:true}) -- yyyymmdd (or yyyyddmm, needs more work for US computers).
--> {"2010/30/03", "2012.11.09", "2000-01-01", "2002:02:02", "2043 12 31", "1943_12_31", "1949b03a09", "2007d07c07"}
NormalizeDates(myDates, {delim:"."}) -- Impose the separator ".".
--> {"03.30.2010", "09.11.2012", "01.01.2000", "02.02.2002", "31.12.2043", "31.12.1943", "09.03.1949", "07.07.2007"}
NormalizeDates(myDates, {fs:true, delim:"."}) -- Reverse AND impose separator.
--> {"2010.30.03", "2012.11.09", "2000.01.01", "2002.02.02", "2043.12.31", "1943.12.31", "1949.03.09", "2007.07.07"}

If you wanted the possibility of converting US short dates to yyyymmdd, you could perhaps modify the script so that the fs value, instead of being simply true or false, could be something which told the handler whether the input dates were in ddmmyyyy or mmddyyyy order.


NG

Offline

 

#24 2012-04-03 11:33:10 am

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4638

Re: Is there a better RegEx for this?

Quite slick. I haven't used a parameter list like that before, either. Neat.


iMac & MBP both running OS X 10.9.1

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.059 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)