zoukankan      html  css  js  c++  java
  • 官方的正则表达式组件 RegularExpressions (3) : TMatchEvaluator


    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.
    

  • 相关阅读:
    程序员偷偷深爱的9个不良编程习惯
    JQuery实现放大镜
    ACM1995
    liubo.im
    Linux中的一些点
    EPOLL使用详解
    Elays'Blog
    c#数据库解析
    codeforces #332 div 2 D. Spongebob and Squares
    类型
  • 原文地址:https://www.cnblogs.com/del/p/1998206.html
Copyright © 2011-2022 走看看