#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?:#|//)[^\r\n]*|/\*[\s\S]*?\*/"
Local $sString = "mystring bla bla bla <-- should find this" & @CRLF & _
"bla bla mystring bla <-- also this" & @CRLF & _
"// bla bla mystring <-- not this , because is already commented" & @CRLF & _
"//mystring <-- not this" & @CRLF & _
"// alkdfjñas askfjña bla bla mystring <-- not this" & @CRLF & _
"wsfier mystring añljkfasñf <--should find this" & @CRLF & _
"mystring //a comment <-- should find this" & @CRLF & _
" bla bla // asfsdf mystring <-- should SKIP this, because mystring is commented" & @CRLF & _
"/* " & @CRLF & _
"asdfasf" & @CRLF & _
"mystring <-- i dont care if it finds this, even if it is inside a block comment" & @CRLF & _
"añfkjañsflk" & @CRLF & _
"// aksañl mystring <-- but should skip this, because the single line is already commented with '//' (regardless the block comment) " & @CRLF & _
"" & @CRLF & _
"añskfjñas" & @CRLF & _
"asdasf" & @CRLF & _
"*/"
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH)
; 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