Method Regexp.PCRE2.MatchContext()->set_match_limit()

class Regexp.PCRE2.MatchContext

Method set_match_limit

void set_match_limit(int value)

Description

The match_limit parameter provides a means of preventing PCRE2 from using up too many computing resources when processing patterns that are not going to match, but which have a very large number of possibilities in their search trees. The classic example is a pattern that uses nested unlimited repeats.

There is an internal counter in pcre2_match() that is incremented each time round its main matching loop. If this value reaches the match limit, pcre2_match() returns the negative value ERROR.MATCHLIMIT. This has the effect of limiting the amount of backtracking that can take place. For patterns that are not anchored, the count restarts from zero for each position in the subject string.

When pcre2_match() is called with a pattern that was successfully processed by pcre2_jit_compile(), the way in which matching is executed is entirely different. However, there is still the possibility of runaway matching that goes on for a very long time, and so the match_limit value is also used in this case (but in a different way) to limit how long the matching can continue.