|
Mailing Lists
|
Home / Groups / Regular Expressions (RegEx)
Count word in one line and <enter>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. |
February 12, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||