const regex = /^(\s*)object\s(\w*):\sTcxRadioGroup.*?\n\1end/gms;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(\\s*)object\\s(\\w*):\\sTcxRadioGroup.*?\\n\\1end', 'gms')
const str = `object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 494
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object cxRadioGroup1: TcxRadioGroup
Left = 0
Top = 0
Align = alTop
Caption = 'cxRadioGroup1'
Properties.Items = <>
TabOrder = 0
ExplicitLeft = 24
ExplicitTop = 16
ExplicitWidth = 185
Height = 105
Width = 635
end
object cxRadioGroup2: TcxRadioGroup
Left = 0
Top = 389
Align = alBottom
Properties.Items = <>
TabOrder = 1
ExplicitTop = 293
Height = 105
Width = 635
end
object Panel1: TPanel
Left = 200
Top = 111
Width = 257
Height = 265
Caption = 'Panel1'
TabOrder = 2
object cxRadioGroup3: TcxRadioGroup
Left = 8
Top = 16
Caption = 'cxRadioGroup3'
Properties.Items = <>
TabOrder = 0
Height = 105
Width = 185
end
object cxRadioGroup4: TcxRadioGroup
Left = 8
Top = 144
Properties.Items = <
item
Caption = 'item 1'
end
item
Caption = 'item 2'
end>
TabOrder = 1
Height = 105
Width = 185
end
end
end`;
// 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