#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^(?>(?:""[^""\n]*""|[^;""\n]+)*)""?[^"";\n]*(;.*)"
Local $sString = "Peekaboo ; A comment starts with a semicolon and continues until the EOL" & @CRLF & _
"...unless the semicolon is surrounded by unescaped dquotes "Don’t do it ; here" ;but match me; once" & @CRLF & _
"Im not surrounded "so pay attention to me" ; "peekaboo"" & @CRLF & _
"Im not surrounded "so pay attention" to;me" ; "peekaboo"" & @CRLF & _
"Im not surrounded "so pay attention to me ; peekaboo" & @CRLF & _
"Dquote escapes a dquote so "dont pay attention to ""me;here"" buster" do it ; here" & @CRLF & _
"Don’t pay attention to """me;here""" but do ""it;here""" & @CRLF & _
"and "dont do ""it;here""" either ;peekaboo" & @CRLF & _
"but "pay attention to "it;here"" ;not here though" & @CRLF & _
"Simon said "I like goats" then he added "and sheep;" ;a good comment is "here" & @CRLF & _
"Simon said "I like goats" then he added "and sheep;" dont do it here" & @CRLF & _
"Simon said ""I like goats;"peekaboo" & @CRLF & _
"Simon said "I like goats;""peekaboo"
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