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)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 江口县| 恭城| 分宜县| 伊春市| 博罗县| 天等县| 溧水县| 马公市| 九江市| 上林县| 宜兰市| 津南区| 普格县| 芷江| 饶河县| 磐安县| 怀远县| 永康市| 浏阳市| 乡城县| 大埔区| 山阴县| 和顺县| 绥德县| 盐边县| 当阳市| 泗水县| 阿拉善左旗| 韩城市| 安福县| 平陆县| 金沙县| 宁德市| 宁晋县| 宝丰县| 青海省| 盐城市| 中西区| 明水县| 张家界市| 永和县|