[英]QTP/VBScript: How to remove all URLs from a string?
我的QTP測試項目中有一個字符串。 在某些情況下,此字符串是純文本電子郵件的內容。 在其他情況下是HTML。 在這兩種情況下,我都需要從字符串中剝離所有URL,以使其與Expected情況匹配。
如何在QTP / VBScript中完成?
這應該可以解決問題,盡管您的網址需要以http://或https://開頭,才能使用它們:
Dim text
text = "<your text with URLs here>"
Dim rgx
Set rgx = New RegExp
rgx.IgnoreCase = True
rgx.Global = True
rgx.Pattern = "([A-Za-z]{3,9})://([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((/[-\+~%/\.\w]+)?\??([-\+=&;%@\.\w]+)?#?([\w]+)?)?"
Dim match, matches
Set matches = rgx.Execute(text)
For Each match in matches
MsgBox match.Value, 0, "Found Match"
Next
匹配URL的正則表達式模式來自Chris Freyer的博客 ,似乎可以處理您可能會遇到的大多數URL類型。 它在我執行的測試中效果很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.