Php regex: remove order by from query string
问题 I have a php method, which should remove all occurences of an "order by" mysql statement from a mysql query string. Example 1: STRING: SELECT * FROM table ORDER BY name RESULT: SELECT * FROM table Example 2: STRING: SELECT a.* FROM (SELECT * FROM table ORDER BY name, creation_date) AS a ORDER BY a.name Result: SELECT a.* FROM (SELECT * FROM table) AS a My question now is: How to achive this. I have tried the following: if (stripos($sql, 'ORDER BY') !== false) { $sql = preg_replace('/\sORDER\