PCRESTACK(3) PCRESTACK(3) NAME PCRE - Perl-compatible regular expressions PCRE DISCUSSION OF STACK USAGE When you call pcre_exec(), it makes use of an internal function called match(). This calls itself recursively at branch points in the pattern, in order to remember the state of the match so that it can back up and try a different alternative if the first one fails. As match- ing proceeds deeper and deeper into the tree of possi- bilities, the recursion depth increases. Not all calls of match() increase the recursion depth; for an item such as a* it may be called several times at the same level, after matching different numbers of a's. Furthermore, in a number of cases where the result of the recursive call would immediately be passed back as the result of the current call (a "tail recursion"), the function is just restarted instead. The pcre_dfa_exec() function operates in an entirely different way, and hardly uses recursion at all. The limit on its complexity is the amount of workspace it is given. The comments that follow do NOT apply to pcre_dfa_exec(); they are relevant only for pcre_exec(). You can set limits on the number of times that match() is called, both in total and recursively. If the limit is exceeded, an error occurs. For details, see the sec- tion on extra data for pcre_exec() in the pcreapi docu- mentation. Each time that match() is actually called recursively, it uses memory from the process stack. For certain kinds of pattern and data, very large amounts of stack may be needed, despite the recognition of "tail recursion". You can often reduce the amount of recursion, and there- fore the amount of stack used, by modifying the pattern that is being matched. Consider, for example, this pat- tern: ([^<]|<(?!inet))+ It matches from wherever it starts until it encounters "