3v4l.org

run code in 300+ PHP versions simultaneously
<?php $autocomplete = "BD/AL/ABC/01/18 job developper"; $q = "lol reference=BD/AL/ABC/ test"; $expr = '/reference=\w*/'; $words = explode(' ', $q); $newQ = ''; foreach ($words as $word) { if (preg_match($expr, $word, $matches)) { $reference = str_replace('reference=', '', $word); echo $reference; } else { $newQ = $newQ . ' ' . $word; } } echo $newQ;
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.16, 8.3.0 - 8.3.3
BD/AL/ABC/ lol test

preferences:
136.93 ms | 404 KiB | 182 Q