Upd.: In this solution there single spaces in regex are used. They were mysterious for me in previous code, and should be taken by negate character class.
Comment on Re^4: the case where regex seems to work slower
The spaces are there to split the target string into three parts, before the '*', the star part, and after the star. This prevents trying to match
with a pattern equivalent to /a*a*/ which causes the long matching time you were seeing;