@ 2025-03-29T17:02:44Z <?php
$str = 'IF(1>10, "Large", "Medium")
IF(1>10, IF(44>20, "Large", "Medium"), "Small")
IF(1>10, IF(44>20, "Large", IF(4<5, "Tiny", "Medium")), "Small")
IF(A1>10, IF(A1>20, "Large", IF(A1<5, "Tiny", "Medium")), "Small")';
$pattern =<<<'REGEX'
~
# subpatterns
(?<string> " [^"\\]*+ (?s: \\. [^"\\]* )*+ " ){0}
(?<nparens> \( [^"()]*+ (?: \g<string> [^"()]* | \g<nparens> [^"()]* )*+ \) ){0}
(?<other> [^"()\s,] (?: [^"(),]* [^"()\s,])? ){0}
(?<part> (?: \g<string> | \g<nparens> | \g<other> )* ){0}
# main pattern
IF\( \s* (\g<part>) \s* , \s* (\g<part>) \s*, \s* (\g<part>) \s* \)
~x
REGEX;
//$replacement = '($7) ? ($8) : ($9)';
$replacement = '($5) ? ($6) : ($7)';
do {
$str = preg_replace($pattern, $replacement, $str, -1, $count);
} while ($count);
echo $str;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.4.13 0.012 0.009 17.86 8.4.12 0.011 0.009 20.38 8.4.11 0.012 0.007 18.82 8.4.10 0.006 0.003 18.00 8.4.9 0.010 0.012 17.84 8.4.8 0.012 0.007 18.13 8.4.7 0.004 0.005 19.82 8.4.6 0.010 0.010 17.89 8.4.5 0.026 0.010 17.88 8.4.4 0.005 0.004 18.05 8.3.25 0.010 0.009 18.89 8.3.24 0.010 0.010 16.70 8.3.23 0.013 0.007 16.51 8.3.22 0.005 0.004 16.92 8.3.21 0.005 0.003 16.73 8.3.20 0.012 0.007 16.58 8.3.19 0.007 0.012 16.54 8.3.18 0.014 0.006 16.63 8.3.17 0.011 0.008 16.78 8.3.5 0.007 0.012 16.64 8.2.29 0.012 0.007 20.33 8.2.28 0.008 0.002 16.67
preferences:dark mode live preview ace vim emacs key bindings
27.47 ms | 403 KiB | 5 Q