Delphi expression Syntax (3) matching range

Source: Internet
Author: User
Tags expression range win32

[A-Z]: matches all uppercase letters

var reg: TPerlRegEx;begin
  reg := TPerlRegEx.Create(nil);
  reg.Subject := 'CodeGear Delphi 2007 for Win32';
  reg.RegEx  := '[A-Z]';
  reg.Replacement := '◆';
  reg.ReplaceAll;
  ShowMessage(reg.Subject); //返回: ◆ode◆ear ◆elphi 2007 for ◆ in32
  FreeAndNil(reg);
end;

[A-Z]: matches all lowercase letters

var
  reg: TPerlRegEx;
begin
  reg := TPerlRegEx.Create(nil);
  reg.Subject := 'CodeGear Delphi 2007 for Win32';
  reg.RegEx  := '[a-z]';
  reg.Replacement := '◆';
  reg.ReplaceAll;
  ShowMessage(reg.Subject); //返回: C◆◆◆G◆◆◆ D◆◆◆◆◆ 2007 ◆◆◆ W◆◆32
  FreeAndNil(reg);
end;

[0-9]: Match all numbers

var
  reg: TPerlRegEx;
begin
  reg := TPerlRegEx.Create(nil);
  reg.Subject := 'CodeGear Delphi 2007 for Win32';
  reg.RegEx  := '[0-9]';
  reg.Replacement := '◆';
  reg.ReplaceAll;
  ShowMessage(reg.Subject); //返回: CodeGear Delphi ◆◆◆◆ for Win ◆◆
  FreeAndNil(reg);
end;

Match several ranges

var
  reg: TPerlRegEx;
begin
  reg := TPerlRegEx.Create(nil);
  reg.Subject := 'CodeGear Delphi 2007 for Win32';
  reg.RegEx  := '[C-Do-p0-2]'; //大写字母: C-D; 小写字母: o-p; 数字 : 0-2
  reg.Replacement := '◆';
  reg.ReplaceAll;
  ShowMessage(reg.Subject); //返回: ◆◆deGear ◆el◆hi ◆◆◆7 f◆r Win3◆
  FreeAndNil(reg);
end;

Match all in []

var
  reg: TPerlRegEx;
begin
  reg := TPerlRegEx.Create(nil);
  reg.Subject := 'CodeGear Delphi 2007 for Win32';
  reg.RegEx  := '[Ci2]'; //大写字母: C; 小写字母: i; 数字: 2
  reg.Replacement := '◆';
  reg.ReplaceAll;
  ShowMessage(reg.Subject); //返回: ◆odeGear Delph◆ ◆007 for W◆ n3◆
  FreeAndNil(reg);
end;
^ Exclusion [] Allvar
  reg: TPerlRegEx;
begin
  reg := TPerlRegEx.Create(nil);
  reg.Subject := 'CodeGear Delphi 2007 for Win32';
  reg.RegEx  := '[^Ci0-2]'; //这里排除了大写字母: C; 小写字母: i; 数字: 0-2
  reg.Replacement := '◆';
  reg.ReplaceAll;
  ShowMessage(reg.Subject); //返回: C◆◆◆◆◆◆◆◆◆◆◆◆◆i◆ 200◆◆◆◆◆◆◆i◆◆2
  FreeAndNil(reg);
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.