> -----Original Message-----
> From: Janet MacKay [mailto:[EMAIL PROTECTED]
> Sent: Saturday, November 24, 2007 11:21 PM
> To: CF-Talk
> Subject: Re: looping through each row
> 
> Any regex gurus out there know if there is a pattern to test the number
> of commas in a string? I was thinking something along these lines but
> this doesn't quite do it. I'm lousy at regex ;)
> 
> <cfset list = "1,2,3,,5,,,,9,10">
> <cfset matched = reFindNoCase("([^,]*?,[^,]*?){9,9}", list)>
> <cfif matched gt 0>
>    found exactly 9 commas
> <cfelse>
>    no match
> </cfif>

Something like that should work (eventually) but I think a negative test
might be simpler (and might run faster as well - something to consider for
flat-file processing).

Basically if you want to find if exactly nine of something in a string it
means that the string will be "everything else - 9 somethings" if correct.
So just grab the length of the string, replace the somethings with empty
characters and if the length is the original length - 9 then you've got a
match.

It's been (unfortunately) way too long since I've worked in CF but something
like this:

<cfset list = "1,2,3,,5,,,,9,10">
<cfif (len(list) - 9) EQ len(replace(",", "", list))>
        found exactly 9 commas
<cfelse>
        no match
</cfif>

I call it a "negative" test because instead of focusing on the existance of
your marker you're actually destroying your marker and examining the result
without it.  Your marker has a predictable (and testable) result on the
original that, in this case at least, is simpler to recognize when it's
removed than when it's present.

Jim Davis


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Download the latest ColdFusion 8 utilities including Report Builder,
plug-ins for Eclipse and Dreamweaver updates.
http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293777
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to