The properties and methods of the Tperlregex class of Delphi Regular Expressions (1): Finding
//Find out if there is var reg:tperlregex; begin Reg: = tperlregex.create (nil' codegear Delphi for Win32 '; Reg. RegEx ' \d 'if then ShowMessage (' found 'else showmessage ( ' not found '); Freeandnil (REG); End;
//Lookup exists (Method 2)varReg:tperlregex;beginReg: = Tperlregex.create (Nil); Reg. Subject: =' CodeGear Delphi for Win32 '; Reg. RegEx: =' \d '; Reg. Match;//Perform findifReg. Foundmatch Then//Boolean variable Foundmatch will tell us to find out if there are any resultsShowMessage (' found it ')ElseShowMessage (' not found '); Freeandnil (REG);End;
//Show the first one found var reg:tperlregex; begin Reg: = tperlregex.create (nil' codegear Delphi for Win32 '; Reg. RegEx ' \d 'ifthen//2Else showmessage (' not found '); Freeandnil (REG); End;
//show each and every number found separatelyvarReg:tperlregex; Num:integer;//Count with NumbeginReg: = Tperlregex.create (Nil); Reg. Subject: =' CodeGear Delphi for Win32 '; Reg. RegEx: =' \d '; Num: =0; whileReg. Matchagain Do//matchagain is the next beginShowMessage (Reg. Matchedexpression);//will be displayed separately: 2 0 0 7 3 2Inc. (NUM);End; ShowMessage (IntToStr (num));//6Freeandnil (REG);End;
//Show each of the found and total (another)varReg:tperlregex; Num:integer;//Count with NumbeginReg: = Tperlregex.create (Nil); Reg. Subject: =' CodeGear Delphi for Win32 '; Reg. RegEx: =' \d '; Num: =0;ifReg. Match ThenbeginRepeatShowMessage (Reg. Matchedexpression);//will be displayed separately: 2 0 0 7 3 2Inc. (NUM);until( notReg. Matchagain);End; ShowMessage (IntToStr (num));//6Freeandnil (REG);End;
//The position and length of the target stringvarReg:tperlregex;beginReg: = Tperlregex.create (Nil); Reg. Subject: =' CodeGear Delphi for Win32 '; Reg. RegEx: =' Delphi '; whileReg. Matchagain Do//It is clear that this example can only find one resultbeginShowMessage (Reg. Matchedexpression);//String found: DelphiShowMessage (IntToStr (Reg. Matchedexpressionoffset));//Where it is:ShowMessage (IntToStr (Reg. Matchedexpressionlength));//Its length: 6End; Freeandnil (REG);End;
The properties and methods of the Tperlregex class of Delphi Regular Expressions (1): Finding