2 回答

TA貢獻1833條經驗 獲得超4個贊
正確代碼如下:
'═════代═══碼═══開═══始═════
dim s
s = "Cuilu$Test$007"
function test(str)
if str = "Test" then
test = "True"
else
test = "False"
end if
end function
dim reg
set reg = new regExp
reg.Pattern = "\$(\w+)\$"
Set Matches=reg.Execute(s)
Set oMatch = Matches(0)
'這一個0表示第一個匹配項$test$,vbs中正則比較低級,不能直接識別括號
data=oMatch.SubMatches(0)
'這一個0表示括號的數據test
dim news
news = reg.replace(s,test(data))
msgbox news
'═════代═══碼═══結═══束═════
注意這是vbs文件的寫法,在asp中有一句話可能不是這樣寫(set reg = new regExp,你改回你的寫法就是,我這樣給你是方便你測試,建個vbs文件即可運行看到結果)

TA貢獻1811條經驗 獲得超6個贊
Function test(matchStr, str, matchPos, sourceStr)
if str = "Test" then
test = "True"
else
test = "False"
End Function
news = reg.replace(s,getRef("test"))
--------------
如果有兩個子匹配組,那么Function的參數就變成5個。
3個,參數就是6個,依次類推。
這里的str是第一個子匹配組。
添加回答
舉報