Another Example of RegEx

Another Example of RegEx

I wanted to count the number of words typed in the rich text field to limit the amount of text users can type. Using regular expressions and a list, these three lines of code will do the trick. Note that input.BODY is the rich text form field name.

  1. body_text = (input.BODY).replaceAll(("<(.|\n)+?>"),"");
  2. body_text = (body_text).replaceAll("&nbsp;","");
  3. body_words = body_text.toList(" ").size();
  4. alert(body_words);
Originally, I tried to count the occurance of strings using RegEx, but this currently does not work in Creator, or my understanding of RegEx is wrong on this point.

  1. word_occurance=(body_text).getOccurenceCount(("\b(\w+?)\b"));

I hope others find this useful or can provide improvements.

John M. Whitney