Bad patterns may cause SNRegExp to stack overflow while trying to match strings of sufficient length. This is caused by the use of the Java regular expression engine, which is recursion based. Regular expressions that are susceptible to catastrophic backtracking may cause a stack overflow when run on long strings.

Steps to Reproduce

Using background scripts to run the script below causes a StackOverflow error:

var str = "shifting";
var pattern = "hola";
for (var c = 1; c <= 700; c++) {
str += pattern + "/";
str += "separatorhola}";
gs.print(str.replace(/hola(.|\t)*/, "|"));


  1. If possible, reduce backtracking required by the expression by making all quantifiers reluctant when possible. For example, /hola(.|t)*/ becomes /hola(.|t)*?/. This allows the regular expression engine to immediately return a match when found and not continue to search for a larger match in the string.
  2. If the expression cannot be fixed, the r flag can be used to force the expression to use the Rhino matching engine (and not Java's engine) to match the expression. For example, /hola(.|t)*/ would become /hola(.|t)*/r.

Related Problem: PRB621415

Seen In

Dublin Patch 3
Eureka Patch 7
Eureka Patch 7 Hot Fix 1
Eureka Patch 9
Eureka Patch 9 Hot Fix 1

Fixed In

Fuji Patch 2

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2015-09-12 20:35:02