In order to match only strings containing 5 words or less, i.e. not any five words in a row, you also need to add anchoring to the beginning and end of the string:
^((?:\w+ ?){1,5})$
Example
1
solved Want to find exact 5 strings sentences
In order to match only strings containing 5 words or less, i.e. not any five words in a row, you also need to add anchoring to the beginning and end of the string:
^((?:\w+ ?){1,5})$
1
solved Want to find exact 5 strings sentences