// Iregex attributes and Methods iregex. getgroupnames; {array of subexpression numbers. For example, if two subexpressions exist, the values 0, 1, and 2 are obtained. This is basically useless.} iregex. getgroupnumbers; {same as above, only an integer array is obtained} iregex. groupnamefromnumber (); {It should be the name of the subexpression from the subexpression number; but it is not implemented. It is the number} iregex. groupnumberfromname (); {the same one is opposite; basically none} iregex. ismatch (); {judge whether there is a match; if you only want to know whether it matches, use it as quickly as possible} iregex. match (); {Get An imatch object, which is the first matching result} iregex. matches (); {Get An imatchcollection object; this is a set of matched imatch} iregex. replace (); {replace} iregex. split (); {splits strings Based on expressions. The current version is not well implemented and is useless.} iregex. tostring; {Get expression text} iregex. save (); {Save the expression to the stream} iregex. load (); {retrieve the expression saved by save from the stream} iregex. options; {set of options, read-only; to set options, you can only use the Create method} {here, you need to re-check that only replace} // iregex is implemented through tregex, tregex also has the following static class Methods: tregex. escape (); {characters to be escaped} tregex. unescape (); {restores escape encoding} tregex. ismatch (); {same as iregex. ismatch} tregex. match (); {same as iregex. match} tregex. matches (); {same as iregex. matches} tregex. replace (); {same as iregex. replace} tregex. split (); {same as iregex. split} {using these class methods will makeCode Simpler}
The following describes how to simplify the use of class methods.ProgramExample:
Uses regularexpressions; Procedure tform1.formcreate (Sender: tobject); var match: imatch; matchcollection: imatchcollection; pattern, input, STR: string; begin pattern: = '([A-Za-Z] +) (\ D +)'; input: = 'aaa1 bbb2 aa11 bb22 a111 b222 aaa'; // match: = tregex. match (input, pattern); showmessage (match. value); {aaa1} // matchcollection: = tregex. matches (input, pattern); showmessage (inttostr (matchcollection. count); {4} // STR: = tregex. replace (input, pattern, '◆'); showmessage (STR); {◆ AAAA} end;
Test escape and Unescape:
Uses regularexpressions; Procedure tform1.formcreate (Sender: tobject); var STR: string; begin STR: = tregex. Escape ('. $ ^ {[(|) * +? \ '); Showmessage (STR); (* \. \ $ \ ^ \ {\ [\ (\ | \) \ * \ + \? \ *) STR: = tregex. Unescape (STR); showmessage (STR); (*. $ ^ {[(|) * +? \ *) End;
The replace function has many reloads, such:
Uses regularexpressions; Procedure tform1.formcreate (Sender: tobject); var RegEx: iregex; match: imatch; pattern, input, STR: string; begin pattern: = '([A-Za-Z] +) (\ D +)'; input: = 'aaa1 bbb2 aa11 bb22 a111 b222 aaa'; RegEx: = tregex. create (pattern); {replace all} STR: = RegEx. replace (input, '◆'); showmessage (STR); {◆ AAAA} {replace only the first two matches} STR: = RegEx. replace (input, '◆', 2); showmessage (STR); {◆ aa11 bb22 a111 b222 AAAA} {starting from 10th characters, only two matches are replaced} STR: = RegEx. replace (input, '◆', 2, 10); showmessage (STR); {aaa1 bbb2 ◆ a111 b222 AAAA} end;
The replace function should also have a tmatchevaluator event parameter, which can be used to perform more advanced replications. Unfortunately, the current version is not implemented.
Although a lot of things have not yet been implemented, it is quite good to try it out. You can give up perlregex!