Kinda, but not close enough..
First of you are trying to answer more than I am asking for..
Second, dateformat, expects the date to be in US date format, the function I
am working on does not look at the locale or expects a specific format, you
feed it the format it is in and you feed it the format you want it in.
Second, there might be some flaws in it, and there might not be, I am not
even near to being done with it, I simply enquired about look ahead, i.e.
matching something and not consuming it ;-))

- it's not done yet
- it's not called isDate()
- it's reFind witch will give me three sub expressions containing the data I
am after
The syntax I have is way more simpler than what you suggested..
But lets get back on topic, on Monday I will see if (?:/|-) will do what I
am after...

Taco Fleur

Tell me and I will forget
Show me and I will remember
Teach me and I will learn 


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Adam Cameron
> Sent: Saturday, 14 August 2004 9:44 AM
> To: CFAussie Mailing List
> Subject: [cfaussie] Re: [OT] regex
> 
> 
> > What I'm doing is creating a function that reformats a 
> date, i.e. from 
> > mm/dd/yyyy to dd/mm/yyyy etc..
> 
> Kinda like dateFormat(date, "dd/mm/yyyy")?  Why reinvent the wheel?
> 
> But, going back to the way you're going about it...
> 
> Your regexp has a few flaws:
> - It'll match three digit years.
> - It'll match data like 13/32/2004: fits the dd/dd/dddd 
> pattern, but still ain't a date.
> - if you use REreplace(), which seems to be what you're 
> intending, it might not match ANYTHING if the string is 
> malformed, so just return the same malformed string, without 
> you knowing.
> 
> So you need to use REFind() to do it, check to see whether 
> you matched everything you need, in the format you want, and 
> if so; rebuild the string.
> 
> Something like this:
> 
> <cfscript>
>       date1   = "2/1/2004";   // and remember that's being 
> treated as mm/dd/yyyy by
> this code...
>       date2   = "";
> 
>       match = REFind("^(?x)   ## match must be @ beginning of 
> string, and (?x)
> allows me to add comments and make it a multiline regexp
>                       (\d{1,2})               ## 1-2 chars 
> which will be the month part
>                       (/|-)                   ## whichever 
> slash we're using, and recall it for later.  If you
> use ?: here, it doesn't capture it for use two steps further down
>                       (\d{1,2})               ## 1-2 chars 
> which will be the day part 
>                       \2                              ## 
> whichever slash we had earlier
>                       ((\d{2}){0,1})  ## a group of exactly 
> two characters; but either zero or
> one occurences of that; so the (optional) first two positions of YYyy
>                       (\d{2})                 ## two digits 
> (so in total it's possibly exactly two digits
> from above, and definitely another two digits here); so the 
> minimum requirement for year: YY
>                       $                               ## 
> anchored to the end of the string
>                       ",date1, 1, true);
> 
>       if (arrayLen(match.pos) eq 7){
>               dayPart         = mid(date1, match.pos[4], 
> match.len[4]);
>               monthPart       = mid(date1, match.pos[2], 
> match.len[2]);
>               yearPart        = "";
>               if (match.pos[5]){
>                       yearPart = mid(date1, match.pos[5], 
> match.len[5]);
>               }
>               yearPart = yearPart & mid(date1, match.pos[7], 
> match.len[7]);
>               separator = mid(date1, match.pos[3], 
> match.len[3]);        // or you could just
> hard-code "/" here if you liked
>               
>               date2 = numberFormat(dayPart, "00") & separator 
> & numberFormat(monthPart,
> "00") & separator & yearPart;
>               // but it still might not be a date
>       }else{
>               writeOutput("That ain't a date");
>       }
> </cfscript>
> <cfdump var="#match#">
> <cfdump var="#date2#">
> 
> So it's a lot of hassle and doesn't work very well.  Just use 
> dateFormat().
> 
> Adam
> 
> ---
> You are currently subscribed to cfaussie as: 
> [EMAIL PROTECTED] To unsubscribe send a blank email to 
> [EMAIL PROTECTED]
> Aussie Macromedia Developers: http://lists.daemon.com.au/
> 


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
Aussie Macromedia Developers: http://lists.daemon.com.au/

Reply via email to