#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?m)^Q: ((?:.*|\n)*?)\n*A: (.+(?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))*)" & @CRLF & _
""
Local $sString = "Q: diff between null and undefined?" & @CRLF & _
"" & @CRLF & _
"A: Null indicates an intentional empty value. " & @CRLF & _
"- Undefined indicates the total absence of a value. This happen when only the variable was declared without any initializer. A missing key in an object is also undefined. " & @CRLF & _
"```javascript" & @CRLF & _
"export function ticketStatus(tickets, ticketId) {" & @CRLF & _
" if (tickets[ticketId] === undefined) {" & @CRLF & _
" return 'unknown ticket id';" & @CRLF & _
" } else if (tickets[ticketId] === null) {" & @CRLF & _
" return 'not sold';" & @CRLF & _
" } else {" & @CRLF & _
"" & @CRLF & _
" return `sold to ${tickets[ticketId]}`;" & @CRLF & _
" }" & @CRLF & _
"}" & @CRLF & _
"```" & @CRLF & _
"<!--ID: 1673953179724-->" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"---" & @CRLF & _
"Q: rewrite to use [[JS Object.assign]]" & @CRLF & _
"```javascript" & @CRLF & _
"visitor.ticketId = null;" & @CRLF & _
"" & @CRLF & _
"return visitor;" & @CRLF & _
"```" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"A: Just pass only the props we want to overwrite to assign" & @CRLF & _
"```javascript" & @CRLF & _
"return Object.assign(visitor, {ticketId: null});" & @CRLF & _
"```" & @CRLF & _
"<!--ID: 1673953179746-->" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"---" & @CRLF & _
"" & @CRLF & _
"Q: diff between isNaN() global vs Number.isNaN()?" & @CRLF & _
"" & @CRLF & _
"A: global isNaN() does type conversion. " & @CRLF & _
"- Since I am trying to test whether the string contains a valid number, this is the right choice. " & @CRLF & _
"- If the input is already a number, then Number.isNaN() might be better. as" & @CRLF & _
"" & @CRLF & _
"---" & @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