I need a regex which success 0-300 words and fails 301 or more words.
I tried:
^\s*(\S+\s+){0,300}\S*$
I also checked
^\W*(?:\w+\b\W*){0,300}$
Both are working fine but in Java I get a java.lang.StackOverflowError. I know using a larger "XSS" I get around this issue but I wanted to ask if there is a way to optimize the regex?