I am using Regular Expressions to code the last characters in an SQL statement, for example the operator - e.g if the SQL statement consist of WHERE keyword LIKE 100, then it must search for LIKE. But now I want to add DISTINCT in front of the field name, for example DISTINCT keyword, in the same regex. I am having difficulties with the front character that must be DISTINCT. Ant help please?
$operator = preg_match("/(^DISTINCT\s)\s(NOT|LIKE|NOT LIKE|\<|\>|\!\=)$/", $field, $matches);
$oplength = strlen($matches[0]);
if(strpos($field, $matches[0])) {
$field = trim(substr($field, 0, -$oplength));
}
else {
$matches[0] = '=';
}