Prepare: We first write a search for all English words in the expression var Reg:tperlregex;
BEGIN REG: = Tperlregex.create (nil); Reg.
Subject: = ' One Two three four five six seven eight nine '; Reg. RegEx: = ' \b[a-za-z]+\b '; This expression will be able to find all the English word reg.
Replacement: = '; Reg.
ReplaceAll; ShowMessage (Reg. Subject);
Return: Freeandnil (REG);
End What if we just need the first letter of each word?
This will use the subexpression//www.bianceng.cn var Reg:tperlregex;
BEGIN REG: = Tperlregex.create (nil); Reg.
Subject: = ' One Two three four five six seven eight nine '; Reg. RegEx: = ' \b ([a-za-z]) [a-za-z]*\b '; Note that there are child expressions in the expression, Reg in (). Replacement: = ' \1 '; \1 references the first subexpression, Reg.
ReplaceAll; ShowMessage (Reg. Subject);
Back: O t f F S e N T freeandnil (reg);
End
You can have more than one subexpression var reg:tperlregex in an expression;
BEGIN REG: = Tperlregex.create (nil); Reg.
Subject: = ' One two three ten '; Reg.
RegEx: = ' (t) (\w+) '; Reg. Replacement: = ' [\1-\2:\0] '; \1\2 the corresponding subexpression respectively; Refers to the entire expression Reg.
ReplaceAll; ShowMessage (Reg. Subject); //Back: one [t-wo:two] [t-hree:three] [T-en:ten] Freeandnil (REG);
End
When you introduce the methods of the Tperlregex class later, there are more topics about references to (subexpression).