官方的正則表達式組件 RegularExpressions (4) 表達式選項.doc_第1頁
官方的正則表達式組件 RegularExpressions (4) 表達式選項.doc_第2頁
官方的正則表達式組件 RegularExpressions (4) 表達式選項.doc_第3頁
官方的正則表達式組件 RegularExpressions (4) 表達式選項.doc_第4頁
官方的正則表達式組件 RegularExpressions (4) 表達式選項.doc_第5頁
免費預覽已結束,剩余1頁可下載查看

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

TRegExOption = ( roNone, /無 roIgnoreCase, /不區分大小寫 roMultiLine, /多行模式; 可使 和 $ 匹配每個行首或行尾 roExplicitCapture, /只捕獲指定了名稱或編號的子表達式 roCompiled, /預編譯表達式; 這在反復使用更有效率 roSingleLine, /單行模式; 使 . 也可匹配換行符 roIgnorePatternSpace /忽略注釋和未經轉義的空白);uses RegularExpressions;roIgnoreCaseprocedure TForm1.Button1Click(Sender: TObject);const pattern = A-Z+d+; txt = AAA1 bbb2 aa11 bb22 A111 B222 AAAA;var match: TMatch;begin Memo1.Clear; for match in TRegEx.Matches(txt, pattern, roIgnoreCase) do begin Memo1.Lines.Add(match.Value); end; Memo1.Lines.Add(-); for match in TRegEx.Matches(txt, pattern) do begin Memo1.Lines.Add(match.Value); end;end;*AAA1bbb2aa11bb22A111B222-AAA1A111B222*roMultiLineprocedure TForm1.Button2Click(Sender: TObject);const txt = Delphi Delphi Delphi#13#10Delphi Delphi Delphi;var rStr: string;begin Memo1.Clear; 行首 rStr := TRegEx.Replace(txt, Delphi, ., roMultiLine); Memo1.Lines.Add(rStr); Memo1.Lines.Add(-); rStr := TRegEx.Replace(txt, Delphi, .); Memo1.Lines.Add(rStr); Memo1.Lines.Add(-); 行尾 rStr := TRegEx.Replace(txt, Delphi$, ., roMultiLine); Memo1.Lines.Add(rStr); Memo1.Lines.Add(-); rStr := TRegEx.Replace(txt, Delphi$, .); Memo1.Lines.Add(rStr);end;*. Delphi Delphi. Delphi Delphi-. Delphi DelphiDelphi Delphi Delphi-Delphi Delphi .Delphi Delphi .-Delphi Delphi DelphiDelphi Delphi .*roExplicitCaptureprocedure TForm1.Button3Click(Sender: TObject);const pattern1 = (A-Z+)(d+); pattern2 = (?A-Z+)(d+); pattern3 = (A-Z+)(?d+); txt = AA11 BB22;var match: TMatch; group: TGroup;begin Memo1.Clear; for match in TRegEx.Matches(txt, pattern1, roExplicitCapture) do begin for group in match.Groups do begin Memo1.Lines.Add(group.Value); end; end; Memo1.Lines.Add(-); for match in TRegEx.Matches(txt, pattern1) do /此處把 pattern1 換做 pattern2 或 pattern3 均可 begin for group in match.Groups do begin Memo1.Lines.Add(group.Value); end; end; Memo1.Lines.Add(-); for match in TRegEx.Matches(txt, pattern2, roExplicitCapture) do begin for group in match.Groups do begin Memo1.Lines.Add(group.Value); end; end; Memo1.Lines.Add(-); for match in TRegEx.Matches(txt, pattern3, roExplicitCapture) do begin for group in match.Groups do begin Memo1.Lines.Add(group.Value); end; end;end;*AA11BB22-AA11AA11BB22BB22-AA11AABB22BB-AA1111BB2222*roCompiledprocedure TForm1.Button4Click(Sender: TObject);var reg: TRegEx;begin reg := TRegEx.Create(d+, roCompiled); Memo1.Text := reg.Replace(AA11 BB22, .); /AA. BB.end;roSingleLineprocedure TForm1.Button5Click(Sender: TObject);const pattern = A-Z1.1; txt = A B C D#13#10A B C D#13#10A B C D;var rStr: string;begin Memo1.Clear; rStr := TRegEx.Replace(txt, pattern, 11, roSingleLine); Memo1.Lines.Add(rStr); Memo1.Lines.Add(-); rStr := TRegEx.Replace(txt, pattern, 11); Memo1.Lines.Add(rStr);end;*1111111111111111111111D-111111D111111D111111D*roIgnorePatternSpaceprocedure TForm1.Button6Click(Sender: TObject);var rStr: string;begin Memo1.Clear; 忽略空白 rStr := TRegEx.Replace(ABC,A B C,AB C, AB C, ., roIgnorePatternSpace); Memo1.Lines.Add(rStr); /.,A B C,AB C rStr := TRegEx.Replace(ABC,A B C,AB C, AB C, .); Memo1.Lines.Add(rStr); /ABC,A B C,. Memo1.Lines.Add(-); 使用注釋 rStr := TRegEx.Replace(ABC123, ABC#*123, ., roIgnorePatternSpace); Memo1.Lines.Add(rStr); /.123 rStr := TRegEx.Replace(ABC123, ABC#*123, .); Memo1.Lines.Add(rStr); /.end;*.,A B C,AB CABC,A B C,.-.123.*選項集合procedure TForm1.Button7Click(Sender: TObject);const pattern =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論