Attributes and methods of tperlregex in Delphi regular expression (1): Search

Source: Internet
Author: User
// Check whether var REG: tperlregex; begin REG: = tperlregex exists. create (NiL); Reg. subject: = 'codegear Delphi 2007 for Win32 '; Reg. regEx: = '\ d'; If Reg. match then showmessage ('found') else showmessage ('not found'); freeandnil (REG); end;
  
   
 // Find whether there is (method 2) var REG: tperlregex; begin REG: = tperlregex. create (NiL); Reg. subject: = 'codegear Delphi 2007 for Win32 '; Reg. regEx: = '\ d'; Reg. match; // execute the search If Reg. foundmatch then // The Boolean variable foundmatch will tell us whether the result is showmessage ('found ') else showmessage ('not found'); freeandnil (REG); end;
  
   
 // Display the first var REG: tperlregex; begin REG: = tperlregex. create (NiL); Reg. subject: = 'codegear Delphi 2007 for Win32 '; Reg. regEx: = '\ d'; If Reg. match then showmessage (Reg. matchedexpression) // 2 else showmessage ('not found'); freeandnil (REG); end;
  
   
 // Display each and all found values respectively. var REG: tperlregex; num: integer; // use num to count begin REG: = tperlregex. create (NiL); Reg. subject: = 'codegear Delphi 2007 for Win32 '; Reg. regEx: = '\ d'; num: = 0; while Reg. matchagain do // matchagain is the next begin showmessage (Reg. matchedexpression); // the following values are displayed: 2 0 0 7 3 2 Inc (Num); end; showmessage (inttostr (Num); // 6 freeandnil (REG); end;
  
   
 // Display each and all found items respectively (in another way) var REG: tperlregex; num: integer; // use num to count begin REG: = tperlregex. create (NiL); Reg. subject: = 'codegear Delphi 2007 for Win32 '; Reg. regEx: = '\ d'; num: = 0; If Reg. match then begin repeat showmessage (Reg. matchedexpression); // It will be displayed respectively: 2 0 0 7 3 2 Inc (Num); until (not Reg. matchagain); end; showmessage (inttostr (Num); // 6 freeandnil (REG); end;
  
   
 // The position and length of the target string var REG: tperlregex; begin REG: = tperlregex. create (NiL); Reg. subject: = 'codegear Delphi 2007 for Win32 '; Reg. regEx: = 'delphi '; while Reg. matchagain do // obviously: In this example, only one result can be found: Begin showmessage (Reg. matchedexpression); // The string found: Delphi showmessage (inttostr (Reg. matchedexpressionoffset); // Its location: 10 showmessage (inttostr (Reg. matchedexpressionlength); // Its length: 6 end; freeandnil (REG); end;
  
   
 

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.