regex-search
regex-search copied to clipboard
Expressions with the * operator runs infinitely
On this page: http://docs.oracle.com/javase/tutorial/essential/concurrency/procthread.html
I searched s* and it appears to enter an infinite loop in v 1.8. Eventually, the page crashes.
Whoa... well this is bad. I'm not sure what the proper fix is for this or when I'll get time to look into it, but thanks for the report.
I can confirm this.
Please use s+
(at least one s) instead. It is more efficient than s*
(0 or more s) because the latter even matches empty strings all over the page.
Maybe we should disallow searching any two character regex where the second character is a '', or the one character regex where '' is the only character. Does that cover all of the bad cases or are there other cases we're missing?
Some test cases performed on the website mentioned in the first comment:
1 works: .*
2 works: ..........
3 works: .*.*.*.*.*.*.*
4 works: (.+)*
5 fails: s*
It seems that some optimization is done in case 1 as opposed to case 5.
So indeed, it might be a good idea to disallow a regex consisting of any character followed by * only. Or shall we rather add general hint/warning that usage of '+' is encouraged contrary to '*'
PS: You can escape asterisks and other Markdown syntax by a backslash: \ *