01、Delphi正则表达式
01、先写个正则表达式小工具,再用这个工具测试和学习。

02.代码如下:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.Mask, System.Types, System.RegularExpressions; type TForm1 = class(TForm) GroupBox1: TGroupBox; Button1: TButton; Memo1: TMemo; Splitter1: TSplitter; ListView1: TListView; LabeledEdit1: TLabeledEdit; procedure Button1Click(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } m_StrList: TStringList; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses TxCommon; procedure TForm1.Button1Click(Sender: TObject); var m_Source: string; m_Pattern: string; m_Match: TMatch; I: Integer; begin I := 0; m_Source := Memo1.Text; m_Pattern := LabeledEdit1.Text; ListView1.Items.Clear; for m_Match in TRegEx.Matches(m_Source, m_Pattern) do begin // 增加记录 with ListView1.Items.Add do begin I := I + 1; Caption := I.ToString; Subitems.Add(m_Match.Value); end; end; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin m_StrList.Free; end; procedure TForm1.FormShow(Sender: TObject); begin m_StrList := TStringList.Create; end; end.

浙公网安备 33010602011771号