//匹配右边 var reg: TPerlRegEx; begin reg := TPerlRegEx.Create(nil); reg.Subject := ‘Delphi 6; Delphi 7; Delphi 2007; Delphi Net‘; reg.RegEx := ‘Delphi (?=2007)‘; // ?= reg.Replacement := ‘◆‘; reg.ReplaceAll; ShowMessage(reg.Subject); //返回: Delphi 6; Delphi 7; ◆2007; Delphi Net FreeAndNil(reg); end;
//不匹配右边 var reg: TPerlRegEx; begin reg := TPerlRegEx.Create(nil); reg.Subject := ‘Delphi 6; Delphi 7; Delphi 2007; Delphi Net‘; reg.RegEx := ‘Delphi (?!2007)‘; // ?! reg.Replacement := ‘◆‘; reg.ReplaceAll; ShowMessage(reg.Subject); //返回: ◆6; ◆7; Delphi 2007; ◆Net FreeAndNil(reg); end;
//匹配左边 var reg: TPerlRegEx; begin reg := TPerlRegEx.Create(nil); reg.Subject := ‘111, 222, ¥333, ¥444‘; reg.RegEx := ‘(?<=¥)\d{3}‘; // ?<= reg.Replacement := ‘◆‘; reg.ReplaceAll; ShowMessage(reg.Subject); //返回: 111, 222, ¥◆, ¥◆ FreeAndNil(reg); end;
//不匹配左边 var reg: TPerlRegEx; begin reg := TPerlRegEx.Create(nil); reg.Subject := ‘111, 222, ¥333, ¥444‘; reg.RegEx := ‘(?<!¥)\d{3}‘; // ?<! reg.Replacement := ‘◆‘; reg.ReplaceAll; ShowMessage(reg.Subject); //返回: ◆, ◆, ¥333, ¥444 FreeAndNil(reg); end;