Parentheses in the expression will seriously affect the split result.
Uses regularexpressions; const fsourcetext = '1: AAA 2: BBB 3: CCC '; // The delimiter consists of three parts: a number, a colon, and a space var arr: tarray
; STR: string; Procedure tform1.button1click (Sender: tobject); begin arr: = tregex. split (fsourcetext, '\ D:'); memo1.clear; for STR in arr do memo1.lines. add (STR); {result: aaa bbb ccc} end; Procedure tform1.button2click (Sender: tobject); begin arr: = tregex. split (fsourcetext, '(\ D):'); // the part in the brackets is treated as the split element memo1.clear; for STR in arr do memo1.lines. add (STR); {1 AAA 2 BBB 3 CCC} end; Procedure tform1.button3click (Sender: tobject); begin arr: = tregex. split (fsourcetext, '(\ D :)'); // verify the preceding memo1.clear; for STR in arr do memo1.lines. add (STR); {1: AAA 2: BBB 3: CCC} end; Procedure tform1.button4click (Sender: tobject); begin arr: = tregex. split (fsourcetext, '(\ D) (:)'); // if there are two parentheses, take the content of the parentheses as the element memo1.clear; for STR in arr do memo1.lines. add (STR); {: AAA: BBB: CCC} end; Procedure tform1.button5click (Sender: tobject); begin arr: = tregex. split (fsourcetext, '(\ D) (:) ()'); // verify the preceding memo1.clear; for STR in arr do memo1.lines. add (STR); {aaa bbb ccc} end;