qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          QTP VBScript RegExp對象的運用

           下面來講講RegExp對象:
            Vbs提供了針對正則表達式的一個非常實用的類,就是RegExp
          Global屬性:代表全局匹配
          IgnoreCase屬性:大小寫忽略
          Pattern屬性:正則表達式
          Execute方法:匹配搜索,返回匹配結果集合
          Replace方法:匹配代替,返回替代匹配結果
          Test方法:測試匹配,返回布爾類型
            下面舉幾個實例:
          '判斷正則匹配是否正確
          'msgbox (IsRegMatch("a123","http://www.123.456.com"))
          Function IsRegMatch(patrn,str)
          Dim regEx
          Set regEx = New RegExp
          regEx.Pattern = patrn
          regEx.IgnoreCase = False
          IsRegMatch = regEx.Test(str)
          Set regEx = nothing
          End Function
          '替換匹配字符串
          'msgbox (ReplaceRegMatch("9","loader runner 9.0, qtp 9.0","10"))
          Function ReplaceRegMatch(patrn,str,replaceStr)
          Dim regEx
          Set regEx = New RegExp
          regEx.Pattern = patrn
          regEx.IgnoreCase = False
          regEx.Global = True   'false的時候只會替換第一個匹配的字符串。若為true則會替換所有匹配的字符串
          ReplaceRegMatch = regEx.Replace(str,replaceStr)
          End Function
          '返回匹配內容
          'returnRegMatch "qtp .","qtp 1 qtp 2 qtp3 qtp 4"
          Function ReturnRegMatch(patrn,str)
          Dim regEx,matches,match
          Set regEx = New RegExp
          regEx.Pattern = patrn
          regEx.IgnoreCase = true
          regEx.Global = true  '打開全局搜索
          Set matches = regEx.Execute(str)
          For Each match in matches
          print cstr(match.firstIndex) + " " + match.value + " " + cstr(match.length)
          Next
          End Function

          posted on 2014-04-09 10:31 順其自然EVO 閱讀(460) 評論(0)  編輯  收藏 所屬分類: qtp

          <2014年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 五指山市| 英吉沙县| 化隆| 南召县| 邵阳县| 东港市| 罗山县| 安平县| 菏泽市| 红桥区| 滦南县| 阿克| 承德市| 石景山区| 古交市| 亚东县| 普洱| 麻江县| 东兰县| 遂溪县| 五莲县| 积石山| 桃源县| 台州市| 车致| 新兴县| 辽宁省| 县级市| 淮阳县| 乌鲁木齐市| 湘西| 林口县| 怀化市| 榆中县| 绥中县| 夏津县| 万年县| 岱山县| 海门市| 扬州市| 淮安市|