加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

官方的正则表达式组件 RegularExpressions (3) : TMatchEvaluato

发布时间:2020-12-14 04:37:24 所属栏目:百科 来源:网络整理
导读:unit Unit1;interfaceuses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,RegularExpressions;type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private fun

unit Unit1;

interface

uses
  Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,RegularExpressions;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    function MyMatchEvaluator(const Match: TMatch): string; //TMatchEvaluator = function(const Match: TMatch): string of object;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
  pattern = '[A-Z]+d+';
  txt = 'AAA1 BBB2 AA11 BB22 A111 B222 AAAA';

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Text := TRegEx.Replace(txt,pattern,MyMatchEvaluator); //aaa1 bbb2 aa11 bb22 a111 b222 AAAA
end;

function TForm1.MyMatchEvaluator(const Match: TMatch): string;
begin
  Result := LowerCase(Match.Value);
end;

end.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读