const regex = /(\w*field\(.*; ?)(.*\))/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\w*field\\(.*; ?)(.*\\))', 'g')
const str = ` field(Overdue; Overdue)
{
ApplicationArea = Suite;
Caption = 'Overdue';
Editable = false;
ToolTip = 'Specifies that the approval is overdue.';
}
field("Table ID"; "Table ID")
{
ApplicationArea = Suite;
ToolTip = 'Specifies the ID of the table where the record that is subject to approval is stored.';
Visible = false;
}`;
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