I\'m trying to come up with a regular expression to remove comments from an SQL statement.
This regex almost works:
(/\\*([^*]|[\\r\\n]|(\\*+([^*/]|
This code works for me:
function strip_sqlcomment ($string = '') { $RXSQLComments = '@(--[^\r\n]*)|(\#[^\r\n]*)|(/\*[\w\W]*?(?=\*/)\*/)@ms'; return (($string == '') ? '' : preg_replace( $RXSQLComments, '', $string )); }
with a little regex tweak it could be used to strip comments in any language