title: PHP PREG_JIT_STACKLIMIT_ERROR - inefficient regex
body: <p>I am getting PREG_JIT_STACKLIMIT_ERROR error in <code>preg_replace_callback()</code> function when working with a bit longer string. Above 2000 characters it is not woking (above 2000 characters that match regex, not 2000 character string).<br>
  I've read already that it's caused by inefficient regex, but I can't make my regex simpler. Here's my regex:</p>
  
  <p><code>/\{@([a-z0-9_]+)-((%?[a-z0-9_]+(:[a-z0-9_]+)*)+)\|(((?R)|.)*)@\}/Us</code></p>
  
  <p>It should match strings like these:</p>
  
  <p>1) <code>{@if-statement|echo this|echo otherwise@}</code></p>
  
  <p>2) <code>{@if-statement:sub|echo this|echo otherwise@}</code></p>
  
  <p>3) <code>{@if-statement%statament2:sub|echo this@}</code></p>
  
  <p><strong>and also nested</strong> like this:</p>
  
  <p>4) <code>{@if-statement|echo this|
        {@if-statement2|echo this|echo otherwise@}
      @}</code></p>
  
  <p>I've tried to simplify it to: </p>
  
  <p><code>/\{@([a-z0-9_]+)-([a-z0-9_]+)\|(((?R)|.)*)@\}/Us</code></p>
  
  <p>But it looks like error is caused by <code>(((?R)|.)*)</code> part. Any advice?</p>
  
  <p>Code for testing:</p>
  
  <pre><code>$string = '{@if-is_not_logged_homepage|
  &lt;header id="header_home"&gt;
      &lt;div class="in"&gt;
          &lt;div class="top"&gt;
              &lt;h1 class="logo"&gt;&lt;a href="/"&gt;&lt;img src="/img/logo-home.png" alt=""&gt;&lt;/a&gt;&lt;/h1&gt;
              &lt;div class="login_outer_wrapper"&gt;
                  &lt;button id="login"&gt;&lt;div class="a"&gt;&lt;i class="stripe"&gt;&lt;i&gt;&lt;/i&gt;&lt;/i&gt;Log in&lt;/div&gt;&lt;/button&gt;
                  &lt;div id="login_wrapper"&gt;
                      &lt;form method="post" action="{^login^}" id="form_login_global"&gt;
                          &lt;div class="form_field no_description"&gt;
                              &lt;label&gt;{!auth:login_email!}&lt;/label&gt;
                              &lt;div class="input"&gt;&lt;input type="text" name="form[login]"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form_field no_description password"&gt;
                              &lt;label&gt;{!auth:password!}&lt;/label&gt;
                              &lt;div class="input"&gt;&lt;input type="password" name="form[password]"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="remember"&gt;
                              &lt;input type="checkbox" name="remember" id="remember_me_check" checked&gt;
                              &lt;label for="remember_me_check"&gt;&lt;i class="fa fa-check" aria-hidden="true"&gt;&lt;/i&gt;Remember&lt;/label&gt;
                          &lt;/div&gt;
                          &lt;div class="submit_box"&gt;
                              &lt;button class="btn btn_check"&gt;Log in&lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="content clr"&gt;
              &lt;div class="main_menu"&gt;
                  &lt;a href=""&gt;
                      &lt;i class="ico a"&gt;&lt;i class="fa fa-lightbulb-o" aria-hidden="true"&gt;&lt;/i&gt;&lt;/i&gt;
                      &lt;span&gt;Idea&lt;/span&gt;
                      &lt;div&gt;&amp;nbsp;&lt;/div&gt;
                  &lt;/a&gt;
                  &lt;a href=""&gt;
                      &lt;i class="ico b"&gt;&lt;i class="fa fa-user" aria-hidden="true"&gt;&lt;/i&gt;&lt;/i&gt;
                      &lt;span&gt;FFa&lt;/span&gt;
                  &lt;/a&gt;
                  &lt;a href=""&gt;
                      &lt;i class="ico c"&gt;&lt;i class="fa fa-briefcase" aria-hidden="true"&gt;&lt;/i&gt;&lt;/i&gt;
                      &lt;span&gt;Buss&lt;/span&gt;
                  &lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="text_wrapper"&gt;
  
                  &lt;div&gt;
                      &lt;div class="register_wrapper"&gt;
                          &lt;a id="main_register" class="btn register"&gt;Załóż konto&lt;/a&gt;
                          &lt;form method="post" action="{^login^}" id="form_register_home"&gt;
                              &lt;div class="form_field no_description"&gt;
                                  &lt;label&gt;{!auth:email!}&lt;/label&gt;
                                  &lt;div class="input"&gt;&lt;input type="text" name="form2[email]"&gt;&lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="form_field no_description password"&gt;
                                  &lt;label&gt;{!auth:password!}&lt;/label&gt;
                                  &lt;div class="input tooltip"&gt;&lt;input type="password" name="form2[password]"&gt;&lt;i class="fa fa-info-circle tooltip_open" aria-hidden="true" title="{!auth:password_format!}"&gt;&lt;/i&gt;&lt;/div&gt;
  
                              &lt;/div&gt;
                              &lt;div class="form_field terms no_description"&gt;
                                  &lt;div class="input"&gt;
                                      &lt;input type="checkbox" name="form2[terms]" id="terms_check"&gt;
                                      &lt;label for="terms_check"&gt;&lt;i class="fa fa-check" aria-hidden="true"&gt;&lt;/i&gt;Agree&lt;/label&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="form_field no_description"&gt;
                                  &lt;div class="input captcha_wrapper"&gt;
                                      &lt;div class="g-recaptcha" data-sitekey="{%captcha_public_key%}"&gt;&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="submit_box"&gt;
                                  &lt;button class="btn btn_check"&gt;{!auth:register_btn!}&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/header&gt;
  @}';
  
  $if_counter = 0;
  
  $parsed_view = preg_replace_callback( '/\{@([a-z0-9_]+)-((%?[a-z0-9_]+(:[a-z0-9_]+)*)+)\|(((?R)|.)*)@\}/Us',
          function( $match ) use( &amp;$if_counter ){
              return '&lt;-{'. ( $if_counter ++ ) .'}-&gt;';
          }, $string );
  
  
  var_dump($parsed_view); // NULL
  </code></pre>