#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?xs)["'`][^"'`]*(?!\\)["'`](*SKIP)(*F) # Make sure we're not matching inside of quotes, double quotes or backticks" & @CRLF & _
"|(?m-s:\s*(?:\-{2}|\#)[^\n]*$) # Single line comment" & @CRLF & _
"|(?:" & @CRLF & _
" \/\*.*?\*\/ # Multi-line comment" & @CRLF & _
" (?(?=(?m-s:[\t ]+$)) # Get trailing whitespace if any exists and only if it's the rest of the line" & @CRLF & _
" [\t ]+" & @CRLF & _
" )" & @CRLF & _
")"
Local $sString = "SELECT `#comment inside string`;"
Local $sSubst = ""
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm