Fix 'invalid regular expression stackoverflow' issue