Question: Does anybody have a regular expression that would work to limit the number of words in a response? For instance, I'd like to use it with jQuery validate so I can restrict a textbox/textarea to have say 250 words. The boxes will be plain-text.

I've done some Googling but none of the ones I've found were very good. They mostly centered around doing \b\w+\b but I had trouble getting it work.

Answer: 
Could you try:

```
^(?:\b\w+\b[\s\r\n]*){1,250}$

```

That would limit to 250 words over multiple lines.

I am afraid that the Alan's initial proposition:

```
/^\w+(?:\s+\w+){0,249}$/

```

might be a case of [**catastrophic backtracking**](http://www.regular-expressions.info/catastrophic.html)

> 
> When nesting repetition operators, make absolutely sure that there is only one way to match the same match
> 
> 
>
This worked for me:

```
^\W*(\w+(\W+|$)){1,250}$

```