[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})$

Example

https://regex101.com/r/pN9nQ0/1

1

solved Want to find exact 5 strings sentences