3v4l.org

run code in 300+ PHP versions simultaneously
<?php $regex = <<<REGEX / #starting pattern delimiter (?> #starting atomic group, intended for performance ( #capture group 1 \[ #literal opening square brace (?: #non-capturing group for logic encapsulation (?> #starting atomic group, intended for performance [^[\]]+ #negate character class to match one or more non-square brace characters ) #closing atomic group | #or (?1) #recurse the subpattern contained within the first capture group )* #close non-capturing group and allow it to be repeated zero or more times \] #literal closing square brace ) #close capture group 1 | #or [^,[\]]+ #negate character class to match one or more non-square brace characters and non-commas )+ #close atomic group and require one or more matches of internal logic \K #forget previously matched characters to prevent losing them during splitting ,? #optionally match a comma /x REGEX; /* (cannot comment after pattern end) x modifier enables inline regex commenting */ var_export( preg_split( $regex, /* '/(?>(\[(?:(?>[^[\]]+)|(?1))*\])|[^,[\]]+)+\K,?/', */ "first,second[,b],third[a,b[1,2,3]],fourth[a[1,2]],sixth", 0, PREG_SPLIT_NO_EMPTY ) );
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
array ( 0 => 'first', 1 => 'second[,b]', 2 => 'third[a,b[1,2,3]]', 3 => 'fourth[a[1,2]]', 4 => 'sixth', )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
112.69 ms | 407 KiB | 5 Q