You don't need to use regex for that
https://laravel.com/docs/9.x/requests#retrieving-input-from-the-query-string
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have some input as filters for index api like status=1 or age>=23 and etc. I want to extract condition params by preg_match with regex. the result must be like below:
['field' => 'status' ,'operator' => '=', 'value' => 1]
which regex is suitable for?
Something like this should do the trick. But you might want to limit the field ?
preg_match('/^([\w]+)([><=]{1}|[><=]{2})([\w]+)$/', $input, $matches);
$output['field'] = $matches[1];
$output['operator'] = $matches[2];
$output['value'] = $matches[3];
dd($output);
https://laravelplayground.com/#/snippets/af8e528c-15f7-46cb-8299-d51dd7072a15
Please or to participate in this conversation.