1
我有這個正則表達式,它在.Net中工作 - 但不在ASP Classic中。它也適用於RegExrASP經典正則表達式在.Net中的行爲不同於.net
它用於用逗號替換空格,除非空格在引號內。
dim strSearch
dim strPattern
strPattern = "\s(?=(?:[^\x22]*\x22[^\x22]*\x22)*[^\x22]*\z)" '\x22 = " (dbl quotes)
strSearch = The "quick brown" fox jumps
strSearch = ereg_replace(strSearch, pattern, ",", true)
response.write(strSearch)
'Expect: The,"quick brown",fox,jumps
'Actual: The "quick brown" fox jumps
function ereg_replace(strOriginalString, strPattern, strReplacement, varIgnoreCase)
dim objRegExp : set objRegExp = new RegExp
with objRegExp
.Pattern = strPattern
.IgnoreCase = varIgnoreCase
.Global = False
.Multiline = False
end with
ereg_replace = objRegExp.replace(strOriginalString, strReplacement)
set objRegExp = nothing
end function
我需要改變什麼才能使模式適應ASP Classic?
'「\ x22」'不是空格。這是一個雙引號:'''。空格是'「\ x20」' – kirilloid 2012-04-02 19:14:57