// Matchedexpression and subexpressions [0] var REG: tperlregex; begin REG: = tperlregex. create (NiL); Reg. subject: = 'codegear Delphi 2007 '; Reg. regEx: = 'delphi '; while Reg. matchagain do begin showmessage (Reg. matchedexpression); // Delphi; this is the Matching content showmessage (Reg. subexpressions [0]); // Delphi; you can also display the matched content end; {subexpressions is an array: subexpressions [1] stores the content matched by 1st expressions; subexpressions [2] stores content matched by 2nd expressions; subexpressions [N] stores content matched by the nth expression; subexpressions [0] stores content matched by the entire expression; matchedexpression only indicates subexpressions [0].} freeandnil (REG); end;
// Extract the content matching the sub-expression var REG: tperlregex; begin REG: = tperlregex. create (NiL); Reg. subject: = 'abc a1111 bb222 ccc33 dddd4'; Reg. regEx: = '\ B ([A-D] +) ([1-4] +) \ B'; // This expression has two subexpressions that constitute while Reg. matchagain do begin showmessage (Reg. subexpressions [0]); // it will display a1111 bb222 ccc33 dddd4 showmessage (Reg. subexpressions [1]); // it will display a bb ccc dddd showmessage (Reg. subexpressions [2]); // it will display: 1111 222 33 4 {additional: Reg. subexpressioncount is the number of subexpressions; Reg. subexpressionlengths [N] is the length of the string returned by the nth expression; Reg. subexpressionoffsets [N] is the position of the string returned by the nth expression in the source string} end; freeandnil (REG); end;
// The number of subexpressions cannot exceed max_subexpressions = 99. max_subexpressions is the built-in constant of tperlregex.