const regex = /(Dim|Static)(?: )([\S]*)(\(\))?(?: )?(As)? ?(New)? ?([^\r\t\f\v,]*)(,[\S\s][^\n]*)?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(Dim|Static)(?: )([\\S]*)(\\(\\))?(?: )?(As)? ?(New)? ?([^\\r\\t\\f\\v,]*)(,[\\S\\s][^\\n]*)?', 'gm')
const str = `
On Error GoTo Err
Dim obj_AccessApp As Object, Test As xxxy, euaou sai xxx
Set obj_AccessApp = Nothing
Set db_Ref = Nothing
Dim hWndMain As LongPtr
hWndMain = FindWindowEx(0&, 0&, "OMAIN", vbNullString)
Do While hWndMain <> 0
Call z_mGetObjectFromHwnd(hWndMain, obj_AccessApp)
Dim str_DbName As String
str_DbName = ""
On Error Resume Next
str_DbName = obj_AccessApp.CurrentDb.Name
On Error GoTo Err
If str_DbName Like "*\\PPMSupportDb.accdb" Then
On Error Resume Next
obj_AccessApp.CloseCurrentDatabase
obj_AccessApp.Quit
Set obj_AccessApp = Nothing
On Error GoTo 0
Debug.Print "Support item killed"
End If
If str_DbName = "" Then
On Error Resume Next
obj_AccessApp.Quit
Set obj_AccessApp = Nothing
On Error GoTo Err
Debug.Print "Blank item killed"
End If
hWndMain = FindWindowEx(0&, hWndMain, "OMAIN", vbNullString)
Loop
Exit_Default:
Set obj_AccessApp = Nothing
Exit Sub
Err:
MsgBox "GetDatabaseNames" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description
Resume Exit_Default
`;
// 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