I am working on a relatively complex, and very large regular expression. It is currently 41,127 characters, and may grow somewhat as additional cases may be added. I am starting to get this error in PHP:
preg_match_all(): Compilation failed: regular expression is too large at offset 41123
Is there a way to increase the size limit? The following settings suggested elsewhere did NOT work because these apply to size of data and NOT the regex size:
ini_set("pcre.backtrack_limit", "100000000");
ini_set("pcre.recursion_limit", "100000000");
Alternatively, is there a way to define a "sub-pattern variable" within the regex that could be repeated at various places within the regex? (I am not talking about repetition using *
or +
, or even repeating matched "1")? I am actually using PHP variables containing sub-Patterns that are repeated in few places within the regex, but this leads to expansion of the regex BEFORE it is passed on to PRCE functions.
This is a complex regular expression, and cannot be replaced by simpler keyword-searching using strpos
or similar as suggested at this link.
I would prefer to avoid splitting this into sub-expressions at |
and trying to match the sub-expressions separately, because the reduction in size would be modest (there are only 2 or 3 of top-level |
), and this would complicate further development.
\N
whereN
is the group number. This is commonly done when matching quotes like\w+=(['"]).*?\1
(example). But really this could likely be sliced up into many smaller patterns, each processed individually.