官方的正则表达式组件 RegularExpressions (5) : 强测试
发布时间:2020-12-14 01:34:34 所属栏目:百科 来源:网络整理
导读:unit Unit1;interfaceuses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); end;var Form1: TForm1;implemen
unit Unit1; interface uses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses RegularExpressions,msxml; const patternUrl = 'http(s)?://([w-]+.)+[w-]+(/[w- ./?%&=]*)?'; //URL地址 patternEmail = 'w+([-+.'']w+)*@w+([-.]w+)*.w+([-.]w+)*'; //Email地址 patternTel = '((d{3})|d{3}-)?d{8}'; //电话号码 patternIDCard = 'd{17}[d|X]|d{15}'; //身份证号码 {获取网页源码的函数} function GetWebPageText(const AUrl: string): string; begin with CoXMLHTTP.Create do begin open('Get',AUrl,False,EmptyParam,EmptyParam); send(EmptyParam); Result := responseText; end; end; procedure TForm1.Button1Click(Sender: TObject); var txt,url: string; match: TMatch; begin Memo1.Clear; url := 'http://www.google.com.hk/search?hl=zh-TW&source=hp&biw=1440&bih=796&q=Email+%E7%94%B5%E8%AF%9D+%E8%BA%AB%E4%BB%BD%E8%AF%81&btnG=Google+%E6%90%9C%E5%B0%8B&aq=f&aqi=&aql=&oq='; txt := GetWebPageText(url); for match in TRegEx.Matches(txt,patternUrl) do Memo1.Lines.Add(match.Value); Memo1.Lines.Add('--------------------------'); for match in TRegEx.Matches(txt,patternEmail) do Memo1.Lines.Add(match.Value); Memo1.Lines.Add('--------------------------'); for match in TRegEx.Matches(txt,patternTel) do Memo1.Lines.Add(match.Value); Memo1.Lines.Add('--------------------------'); for match in TRegEx.Matches(txt,patternIDCard) do Memo1.Lines.Add(match.Value); Memo1.Lines.Add('--------------------------'); end; end. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |