Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:15:43+00:00 2026-05-31T09:15:43+00:00

<? function recursiveSplit($string, $layer) { $err = preg_match_all("/\{(([^{}]*|(?R))*)\}/",$string,$matches); echo "Elementi trovati: $err<br>"; if($err ==

  • 0
<?

function recursiveSplit($string, $layer) {
    $err = preg_match_all("/\{(([^{}]*|(?R))*)\}/",$string,$matches);
    echo "Elementi trovati: $err<br>";
    if($err == FALSE) echo "preg_match_all ERROR<br>";

    // iterate thru matches and continue recursive split
    if (count($matches) > 1) {
        for ($i = 0; $i < count($matches[1]); $i++) {
            if (is_string($matches[1][$i])) {
                if (strlen($matches[1][$i]) > 0) {
                    echo "<pre>Layer ".$layer.":   ".$matches[1][$i]."</pre><br />";
                    recursiveSplit($matches[1][$i], $layer + 1);
                }
            }
        }
    }
}

$buffer = "{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa{aaaaaaaaaaaaaaaaaa{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}";
recursiveSplit($buffer, 0);

output

Elementi trovati: 
preg_match_all ERROR
Backtrack limit was exhausted!

this code gives me a PREG_BACKTRACK_LIMIT_ERROR error… but the backtrack limit is set to 100.000.000.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:15:44+00:00Added an answer on May 31, 2026 at 9:15 am

    Another classic case of catastrophic backtracking. Must be my lucky day today.

    /\{(([^{}]*|(?R))*)\}/
    

    only matches if the braces are nested correctly. Which they aren’t, of course, in your string.

    Now the problem is that your regex needs to figure out all possible string combinations you can build with 106 as to figure that out because you have nested quantifiers ((...)*)*). Which (correct me if I’m wrong) should be somewhere in the vicinity of 106! which comes to

    114628056373470835453434738414834942870388487424139673389282723476762012382449946252660360871841673476016298287096435143747350528228224302506311680000000000000000000000000

    which easily beats your PREG_BACKTRACK_LIMIT.

    If you use possessive quantifiers to make sure that you’ll never backtrack into the non-braces you’ve already matched, then you should be OK:

    /\{(([^{}]*+|(?R))*)\}/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function strip_cdata($string) { preg_match_all('/<!\[cdata\[(.*?)\]\]>/is', $string, $matches); return str_replace($matches[0], $matches[1], $string); } I use the
function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
function register_contact ($person = array()) { $nogood = false; foreach ($person as $val) {
function _(e) { if (typeof e == 'string') { if (e.charAt(0) == '#') {
function all_images(&$post){ $content = $post->post_content; if(preg_match_all('/<img[^>]+src=(.*?)[^>]*>/', $content, $results)){ $i = 0; $count = count($results);
function test() { var flag1 = false; if ($('#field1').attr('value') || !$('#field1').attr('value')) { $.ajaxSetup({ cache:
Function f(ByVal x As String, ByVal y As Integer, ByVal z As Integer, ByVal
function oneWayEncrypt($string) { $salt = md5($string.yHuJ@8&6%4#%([@d-]); $salt2 = md5($string.@!#&+-)jU@[yT$@%); $string = hash('sha512',$salt$string$salt2); return $string;
function superman(){ //some code var opitem = $(#opinionitem).html(); opitem.replace(:opinionid,valid string); //more code } gives
Function FillAdminAccount() As Boolean FillAdminAccount = True Try SQLconn.ConnectionString = connect timeout=9999999; & _

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.