Attributes and methods of tperlregex in Delphi Regular Expressions (2): subexpressions

Source: Internet
Author: User
// 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.
  
   
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.