#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)(?<!:)(\/\/).+$|\/\*[\s\S]+\*\/"
Local $sString = "// comments at the beginning of the file are removed" & @CRLF & _
"" & @CRLF & _
"/*" & @CRLF & _
"Block comments are removed - easy peasy" & @CRLF & _
"*/" & @CRLF & _
"" & @CRLF & _
"https://urls.are.preserved.for.you// and comments after them are removed" & @CRLF & _
"asdfasdf// the comment can bump right up to text" & @CRLF & _
"asdfasdf;// ...or a semicolon." & @CRLF & _
"" & @CRLF & _
"{" & @CRLF & _
" foo:// you will need a parser to remove this comment b/c it smells like a URL" & @CRLF & _
" "bar",// ...but not this one" & @CRLF & _
" boo: // ...or this one" & @CRLF & _
" "who"" & @CRLF & _
"}"
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
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