Huh? You seem to be asking two questions?

Do you want the number of words in the text (12), or the number of
non-empty lines (2)?


With the behaviour of CF's List functions to ignore empty elements,
you don't need regex, you can simply do:

NumberOfLines = ListLen( Text , Chr(10) )


For the number of words, it is a little more complex - you need to
treat any whitespace as a delimiter:

NumberOfWords = ListLen( Text , ' ' & Chr(13) & Chr(10) & Chr(9) )

This is not perfect (it will treat hyphens, ampersands, etc as words).


If you do want to get actual words only (i.e. , you could try
something like this:

<cfset Words = rematch(String,"\w[\w'-]+") />
<cfoutput>#ArrayLen(Words)# words</cfoutput>

The \w means "word character" whilst the [\w'-] means "word character
or apostrophe or dash", so it will match things like "half-past" and
"o'clock" as single words, but will treat "like - this" or "this &
that" as just 2 words.


Anyway, if this isn't what you're after, you'll need to clarify your question.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: http://www.houseoffusion.com/groups/regex/message.cfm/messageid:1232
Subscription: http://www.houseoffusion.com/groups/regex/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.21

Reply via email to