- preg_match: documentation ( source)
- json_encode: documentation ( source)
<?php
$str = '42 = 42 OR `1+1:3 * 4/2 = 1 \ abc` =2 AND field1=2 AND `column_x` <> "lorem 1" OR a= \'2_\' AND ';
echo json_encode((bool)preg_match(
'/^('.
'(?:`?\w+`?|`[\w+=:\/\*\-\\\ ]+`)\s*'. // column name
'([!><]?=|[><]|<>)\s*'. // operator
'([\'"][\w\s\.\,]+[\'"]|\d+(\.\d+)?)'. // value
'(\s+(AND|OR)\s+)'. // logical operator
')+$/i', $str));