// 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;