有人告诉我用正则表达式,可是我一时还用不明白,请达人指教

解决方案 »

  1.   

    要在word里搜寻"审批人"几个字,它可能是“审 批 人”或者“审 批 人”,应该怎么搜
    // ??
    最佳匹配呀...不太懂得意思..正则表达式..当年编译原理没学好呀....
      

  2.   

    首先安装ScriptControl控件(install-active control -ms scriptcontrol)var
      s:string;
      r:string;
    begin
      s := ' a审批a审 批d 人';
      r := 'var r = new RegExp("审.{0,2}批.{0,2}人", "g");' +
        #13#10'var s = ' + QuotedStr(s) +
        #13#10's.match(r).join("")' ;
      ShowMessage(VarToStr(ScriptControl1.Eval(r)));
    end;
    //替换用    #13#10's.replace(r, "要替换为的文字")' ;
    //new RegExp("审.{0,2}批.{0,2}人", "g"); 这就是正则表达式,研究一下吧。
      

  3.   

    new RegExp("审.{0,2}批.{0,2}人", "g"); 
                  .表示任意字符
                   {0,2}表示在“审”与“批”之间有0到2个字符
                                      g表示查找所有匹配
      

  4.   

    如果需要知道匹配的位置可以使用
        #13#10'r.exec(s).index' ;

        #13#10'r.exec(s).lastIndex' ;
      

  5.   

    晕呼
    就用
    Selection.Find.Execute(FindText:='');
    ''里加你想要的字符串可以加空格
    这是OLE掉用的,不知道符不符合你的要求。
      

  6.   

    我解决了。不过没有用各位达人的,尤其是“windindance(风舞轻扬) ”,因为还需要安装控件。
    我就是用如下的办法:var
      FindText,MatchCase,MatchWholeWord,MatchWildcards,MatchSoundsLike,
      MatchAllWordForms,Oforward,Wrap,Format,ReplaceWith,Replace,WordApp,
      Matchchashida,MatchDiacritics,Matchalef,MatchControl:Variant;
      fordoc:Variant;
      i:integer;
      s:string;
    begin
    OleContainer2.DoVerb(0);
    OleContainer2.Run;
    WordApplication1.Connect;
    fordoc:=WordApplication1.ActiveDocument;
    matchcase := false;
    matchwholeword := true;
    matchwildcards := false;
    matchsoundslike := false;
    matchallwordforms := false;
    Oforward:= true;
    wrap:=1; 
    format:= true
    replace:= true;
    Matchchashida:=false;
    MatchDiacritics:=false;
    Matchalef:=false;
    MatchControl:=false;
    replacewith:='要替换的字符';s:='';
    for i:=1 to 10 do     //最大找10个空格
    begin
       findtext:='审's+'批';   //呵呵,我只找“审批”
    fordoc.range.find.execute( findtext, matchcase, matchwholeword,
    matchwildcards, matchsoundslike, matchallwordforms, Oforward,
    wrap, format, replacewith, replace,
    matchchashida,matchdiacritics,matchalef, matchcontrol);
     s:=s+' ';
    end;