in reply to Re^3: the case where regex seems to work slower
in thread the case where regex seems to work slower

Sorry, I didn't understand your second sentence, because parentheses were not balanced ;)

Thank you for improvement to cope with other cases. I've submitted, and it took only 171 ms at worst TC, this is #93 - http://codeforces.com/contest/832/submission/28930515

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

Replies are listed 'Best First'.
Re^5: the case where regex seems to work slower
by tybalt89 (Monsignor) on Jul 27, 2017 at 13:37 UTC

    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;