Regular Expression is too large error in PHP <p>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:</p> <blockquote> <p>preg_match_all(): Compilation failed: regular expression is too large at offset 41123</p> </blockquote> <p><strong>Is there a way to increase the size limit?</strong> The following settings suggested elsewhere did NOT work because these apply to size of data and NOT the regex size:</p> <pre><code>ini_set("pcre.backtrack_limit", "100000000"); ini_set("pcre.recursion_limit", "100000000"); </code></pre> <p><strong>Alternatively, is there a way to define a "sub-pattern variable" within the regex that could be repeated at various places</strong> within the regex? (I am not talking about repetition using <code>*</code> or <code>+</code>, 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.</p> <p><strong>This is a complex regular expression, and cannot be replaced by simpler keyword-searching</strong> using <code>strpos</code> or similar as suggested at <a href="http://stackoverflow.com/questions/11394697/warning-preg-match-compilation-failed-regular-expression-is-too-large-at-of">this link</a>.</p> <p><strong>I would prefer to avoid splitting this into sub-expressions at <code>|</code></strong> 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 <code>|</code>), and this would complicate further development.</p>