<?php $strings = [ <<<STRING 1 + 2 * (3 + (23 + 53 - (132 / 5) + 5) - 1) + 2 / 'test + string' - 52 STRING, <<<STRING 1+2*(3+(23+53-(132/5)+5)-1)+2/'test+string'-52 STRING ]; foreach ($strings as $str) { var_export( preg_split( "~(?:(\((?:[^()]+|(?1))*\))|'[^']*'|[\d.]+|[*/^+-])\K ?~", $str, -1, PREG_SPLIT_NO_EMPTY ) ); echo "\n"; }
You have javascript disabled. You will not be able to edit any code.