const regex = /(?:(Dim|Public|Private) )(?:(WithEvents) )?(?:(?:(?!Declare)(?!Type)(?!Enum)(?!Const)(\w*))(\(\))?)(?: As )?(?:(New) )?(\w*)(, [\w ,\(\)]*)?/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:(Dim|Public|Private) )(?:(WithEvents) )?(?:(?:(?!Declare)(?!Type)(?!Enum)(?!Const)(\\w*))(\\(\\))?)(?: As )?(?:(New) )?(\\w*)(, [\\w ,\\(\\)]*)?', 'gm')
const str = `Attribute VB_Name = "mdl_WbkInits"
Option Compare Database
Public WithEvents ue_u23 As New String, soumeth_34ing as somethnig, asi As Anthere item, Maybe lastOne
Public ueu As Variant
Dim ueu
Public Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As UUID) As Long
Private Declare Function IIDFromString Lib "ole32" (ByVal lpsz As Long, ByRef lpiid As UUID) As Long
Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hwnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Type UUID 'GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Public Enum e_ControlEventCatch
e_onClick
e_onChange
e_onUpdate
e_onUpdated
e_onDblClick
e_onFocus
e_onExtClick
e_onExtDblClick
e_onActivate
e_onDeActivate
End Enum
Public Const IID_IDispatch As String = "{00020400-0000-0000-C000-000000000046}"
Const OBJID_NATIVEOM As Long = &HFFFFFFF0
`;
// 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