import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(\\s*)object\\s(\\w*):\\sTcxRadioGroup.*?\\n\\1end";
final String string = "object Form1: TForm1\n"
+ " Left = 0\n"
+ " Top = 0\n"
+ " Caption = 'Form1'\n"
+ " ClientHeight = 494\n"
+ " ClientWidth = 635\n"
+ " Color = clBtnFace\n"
+ " Font.Charset = DEFAULT_CHARSET\n"
+ " Font.Color = clWindowText\n"
+ " Font.Height = -11\n"
+ " Font.Name = 'Tahoma'\n"
+ " Font.Style = []\n"
+ " OldCreateOrder = False\n"
+ " PixelsPerInch = 96\n"
+ " TextHeight = 13\n"
+ " object cxRadioGroup1: TcxRadioGroup\n"
+ " Left = 0\n"
+ " Top = 0\n"
+ " Align = alTop\n"
+ " Caption = 'cxRadioGroup1'\n"
+ " Properties.Items = <>\n"
+ " TabOrder = 0\n"
+ " ExplicitLeft = 24\n"
+ " ExplicitTop = 16\n"
+ " ExplicitWidth = 185\n"
+ " Height = 105\n"
+ " Width = 635\n"
+ " end\n"
+ " object cxRadioGroup2: TcxRadioGroup\n"
+ " Left = 0\n"
+ " Top = 389\n"
+ " Align = alBottom\n"
+ " Properties.Items = <>\n"
+ " TabOrder = 1\n"
+ " ExplicitTop = 293\n"
+ " Height = 105\n"
+ " Width = 635\n"
+ " end\n"
+ " object Panel1: TPanel\n"
+ " Left = 200\n"
+ " Top = 111\n"
+ " Width = 257\n"
+ " Height = 265\n"
+ " Caption = 'Panel1'\n"
+ " TabOrder = 2\n"
+ " object cxRadioGroup3: TcxRadioGroup\n"
+ " Left = 8\n"
+ " Top = 16\n"
+ " Caption = 'cxRadioGroup3'\n"
+ " Properties.Items = <>\n"
+ " TabOrder = 0\n"
+ " Height = 105\n"
+ " Width = 185\n"
+ " end\n"
+ " object cxRadioGroup4: TcxRadioGroup\n"
+ " Left = 8\n"
+ " Top = 144\n"
+ " Properties.Items = <\n"
+ " item\n"
+ " Caption = 'item 1'\n"
+ " end\n"
+ " item\n"
+ " Caption = 'item 2'\n"
+ " end>\n"
+ " TabOrder = 1\n"
+ " Height = 105\n"
+ " Width = 185\n"
+ " end\n"
+ " end\n"
+ "end";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html