About tregex. Split ()

Source: Internet
Author: User
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;
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.