const regex = /=\s?.*(?:((?i)Fields\("(\w+)"\)\.Value\)*?))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('=\\s?.*(?:((?i)Fields\\("(\\w+)"\\)\\.Value\\)*?))', 'gm')
const str = `Function lmpRoundedEndTime_ValueChanged(sender, e)
If CDbl(Fields("lmpShiftID").Value) <> 0 And IsNull(Fields("lmpRoundedStartTime").Value) = False And IsNull(Fields("lmpRoundedEndTime").Value) = False Then
If CInt(App.Props("PN").Fields("xapDCPayCalculationMethod").Value) <> 2 Then
Fields("lmpPayrollHours").Value = App.Ax("TimecardFunctions").CalculateHours(Fields("lmpShiftID").Value,Fields("lmpRoundedStartTime").Value,Fields("lmpRoundedEndTime").Value)
'''''''''''' ^ above should capture: lmpShiftID , lmpRoundedStartTime , lmpRoundedEndTime
End If
End If
End Function
Function TimecardLines_SetDefaultValues(sender, e)
Dim oRs,dTimecardDate
dTimecardDate = Null
Set oRs = CreateObject("ADODB.Recordset")
oRs.Open "select lmpEmployeeID,lmpShiftID,lmpTimecardDate,lmpProjectID from Timecards where lmpTimecardID = " + App.Convert.NumberToSql(Fields("lmlTimecardID").Value),Connection,adOpenStatic,adLockReadOnly,adCmdText
If oRs.EOF = False Then
Fields("lmlEmployeeID").Value = oRs.Fields("lmpEmployeeID").Value
Fields("lmlShiftID").Value = oRs.Fields("lmpShiftID").Value
Fields("lmlProjectID").Value = oRs.Fields("lmpProjectID").Value
dTimecardDate = oRs.Fields("lmpTimecardDate").Value
End If
oRs.Close
oRs.Open "select top 1 lmlRoundedEndTime From TimecardLines Where lmlTimecardID = " + App.Convert.NumberToSql(Fields("lmlTimecardID").Value) + " Order By lmlRoundedEndTime Desc",Connection,adOpenStatic,adLockReadOnly,adCmdText
If oRs.EOF = False Then
Fields("lmlRoundedStartTime").Value = oRs.Fields("lmlRoundedEndTime").Value
Else
Fields("lmlRoundedStartTime").Value = App.Ax("Shift").GetDayStartTime(Fields("lmlShiftID").Value, dTimecardDate, e.SqlTransaction)
' Added to to fix -rounded end time is earlier than the rounded start time error when changing the labor hours
'Fields("lmlRoundedEndTime").Value=Fields("lmlRoundedStartTime").Value
End If
oRs.Close
If Trim(Fields("lmlEmployeeID").Value) <> "" Then
oRs.Open "select lmeDirectExpenseID,lmeIndirectExpenseID,lmeDefaultWorkCenterID from Employees where lmeEmployeeID = " + App.Convert.StringToSql(Fields("lmlEmployeeID").Value),Connection,adOpenStatic,adLockReadOnly,adCmdText
If oRs.EOF = False Then
If CInt(Fields("lmlTimecardType").Value) = 1 Then
If Trim(oRs.Fields("lmeDirectExpenseID").Value) <> "" Then
Fields("lmlExpenseID").Value = oRs.Fields("lmeDirectExpenseID").Value
End If
Else
If Trim(oRs.Fields("lmeIndirectExpenseID").Value) <> "" Then
Fields("lmlExpenseID").Value = oRs.Fields("lmeIndirectExpenseID").Value
End If
End If
If CInt(Fields("lmlTimecardType").Value) = 2 Then
If Trim(oRs.FIelds("lmeDefaultWorkCenterID").Value) <> "" Then
Fields("lmlWorkCenterID").Value = oRs.FIelds("lmeDefaultWorkCenterID").Value
End If
End If
End If
oRs.Close
End If
End Function`;
// 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