在 Introduction to Regular Expressions(正則表達式簡介) 一章中的 Backreferences(向后引用)一節(jié):
復制代碼 代碼如下:
'使用上面所示的正則表達式,下面的 JScript 代碼可以使用子匹配信息,在一個文字字符串中將連續(xù)出現兩次的相同單詞替換為一個相同的單詞: var ss = "Is is the cost of of gasoline going up up?./n"; var re = //b([a-z]+) /1/b/gim; //創(chuàng)建正則表達式樣式。 var rv = ss.replace(re,"$1"); //用一個單詞替代兩個單詞。最接近的等價 VBScript 代碼如下:
Dim ss, re, rv ss = "Is is the cost of of gasoline going up up?." & vbNewLine Set re = New RegExp re.Pattern = "/b([a-z]+) /1/b" re.Global = True re.IgnoreCase = True re.MultiLine = True rv = re.Replace(ss,"$1")請注意在 VBScript 代碼中,全局、大小寫敏感性以及多行標記都是使用 RegExp 對象的適當屬性來設置的。