You're running in to crazy backtracking, a common feature in regexes that includes something of the form ([characters]+)+ -- it runs great for all sorts of matching patterns, but then you find a string like this, which makes it explode, recursing all over the string. Here's a sketch of what happens.
To start out, your pattern splits the string into groups. I use a |
to start instances of your group, the one you repeat {1,100}
. >
is the end of a group, and ?
is the regex parser's "cursor."
|----------->|---------->|-------?
Optometrists Association Australia, Queensland/NT Division
At the ?, your pattern can't match any more symbols or whitespace, so it tries to match $. Since the cursor hasn't reached the end of the line yet, it fails, and the regex parser backtracks:
|----------->|---------->|------?
Optometrists Association Australia, Queensland/NT Division
Once again, it can't find any whitespace, so it terminates the group, and tries to start another one (since there can be up to 100, and we've only used 3 so far).
|----------->|---------->|------|-?
Optometrists Association Australia, Queensland/NT Division
The parser has reached the problematic ,
again, and it kills that execution tree, causing it to backtrack once more, to the i
in Australia
. And, just like last time, it tries to start a group:
|----------->|---------->|-----|--?
Optometrists Association Australia, Queensland/NT Division
...anyway, you get the idea. This cycle of fail, backtrack and slice again will effectively freeze up your Regex parser until it's exhausted every permutation and returned false. The key to recognizing and fixing this is to never repeat a repeated group without some form of delimiter at the beginning and/or end. I'd suggest using the word boundary anchor \b
, since [ ]+
would require your strings to end in whitespace:
/^(\b[\w'#@\-\&\(\)\/.]+\b[ ]*){1,100}$/
As a side-note, it's hard to tell what your regex is doing without more context, but it seems like you could also just call value.split(' ')
to split the string on whitespace characters, and run a simpler regex on all those substrings. It'd eliminate the need for the double regex repeat.