On the TRegEx.Split ()

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

The expression in brackets will seriously affect the segmentation results.

uses RegularExpressions;

const
  FSourceText = '1: AAA 2: BBB 3: CCC'; // Separator will have three parts: a digital, a colon, 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): '); //In parentheses is as segmented elements

  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:) '); // Confirm the above

  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 brackets, the brackets behind the content of elements

  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)(:)( )'); // Confirm the above

  Memo1.Clear;
  for str in Arr do Memo1.Lines.Add(str);
  {


  AAA

  BBB

  CCC
  }
end;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by BCv at February 10, 2014 - 11:16 AM