My pattern:
/{LOOP:(\w+)[^}]*}((\s*?.?)*?){\/LOOP:\1}/
My test string:
<tbody>
{LOOP:MENU}
<tr>
<td>{VAR:ID}</td>
<td>{VAR:NAME}</td>
<td>{VAR:ROLLE}</td>
<td>{VAR:ACTIONS}</td>
</tr>
{/LOOP:MENU}
</tbody>
When you try it on regex101 it is working without any problems. But when I try it on my Server with preg_match_all()
it is not working. preg_last_error()
returns:
2(PREG_BACKTRACK_LIMIT_ERROR).
How is that possible with regex101 telling me "1 Match in 581 Steps"? Or has the number of Steps nothing to do with Backtrack?
I'm using apache2 Server with PHP Version 5.5.9-1ubuntu4.16.
In my php.ini, pcre.backtrack_limit
is set on 1000000.
EDIT:
Following the tip of Alan Moore, I now use the following pattern:
/{LOOP:(\w+)[^}]*}(.*?){\/LOOP:\1}/s
This gives back 0(NO_ERROR). But on my server it is now not matching anything. Why is it working on regex101 but not on my server?
PHP:
$test="<tbody>
{LOOP:MENU}
<tr>
<td>{VAR:ID}</td>
<td>{VAR:NAME}</td>
<td>{VAR:ROLLE}</td>
<td>{VAR:ACTIONS}</td>
</tr>
{/LOOP:MENU}
</tbody>"
preg_match_all("/{LOOP:(\w+)[^}]*}(.*?){\/LOOP:\1}/s", $test, $matches, PREG_SET_ORDER);
// $matches is now an emty array.