3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = '( NETR5_2 R6,1 R5,2 ) ( NETR1_2 R4,2 R3,1 R3,2 R2,1 R2,2 R1,1 R1,2 )'; $chunks = explode(")(", preg_replace('/\)\W+\(/m', ')(', $text)); $result = array(); $pattern = '{([A-z0-9,]+)}'; foreach ($chunks as $row) { preg_match_all($pattern, $row, $matches); $result[] = $matches[1]; } print_r($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
Array ( [0] => Array ( [0] => NETR5_2 [1] => R6,1 [2] => R5,2 ) [1] => Array ( [0] => NETR1_2 [1] => R4,2 [2] => R3,1 [3] => R3,2 [4] => R2,1 [5] => R2,2 [6] => R1,1 [7] => R1,2 ) )

preferences:
86.07 ms | 407 KiB | 5 Q