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 閱讀(459) 評論(0)  編輯  收藏 所屬分類: qtp

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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 乌苏市| 四川省| 农安县| 南漳县| 双辽市| 汶川县| 马边| 芜湖市| 汝阳县| 大冶市| 罗源县| 大丰市| 西盟| 墨玉县| 赞皇县| 亚东县| 云龙县| 仁怀市| 平顶山市| 西峡县| 赞皇县| 南雄市| 太仓市| 博爱县| 喀喇| 临夏县| 浦东新区| 凉城县| 桃源县| 会宁县| 来宾市| 滕州市| 门头沟区| 望江县| 昭平县| 贵定县| 汶川县| 宁南县| 长乐市| 筠连县| 屯门区|