const regex = /(?:
"[^"\r\n]*" |
'[^'\r\n]*' |
[^;]
)*
(;\N+)?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:
"[^"\\r\\n]*" |
\'[^\'\\r\\n]*\' |
[^;]
)*
(;\\N+)?', 'gm')
const str = `#include <MsgBoxConstants.au3>
If ProcessExists("SciTE.exe") = 0 Then
MsgBox(\$MB_SYSTEMMODAL, "", "You will need SciTE.exe to be running for ConsoleWrite to display.")
EndIf
Example()
Func Example()
; Register the function MyAdLibFunc() to be called every 250ms (default).
AdlibRegister("MyAdLibFunc")
; Sleep does not stop AdLib functions from running.
Sleep(1000)
; AdLib functions don't run while a blocking function is shown e.g. MsgBox, InputBox, WinWait, WinWaitClose etc.
MsgBox(\$MB_SYSTEMMODAL, "", "No console message(s) will be shown whilst the messagebox is displayed.")
; The AdLib function MyAdLibFunc() will start again.
Sleep(2000)
; Unregister the function MyAdLibFunc() from being called every 250ms.
AdlibUnRegister("MyAdLibFunc")
EndFunc ;==>Example
Func MyAdLibFunc()
; Assign a static variable to hold the number of times the function is called.
Local Static \$iCount = 0
\$iCount += 1
ConsoleWrite("MyAdLibFunc called " & \$iCount & " time(s)" & @CRLF)
EndFunc ;==>MyAdLibFunc
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions