我有这个正则表达式,在.Net中有效 - 但在ASP Classic中没有。它也适用于RegExr
它用于用逗号替换空格,除非空格在引号内。
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?
答案 0 :(得分:4)
我很确定这样做的原因是ASP正则表达式不支持\z
个锚点,请尝试将其替换为$
:
\s(?=(?:[^\x22]*\x22[^\x22]*\x22)*[^\x22]*$)
有关其他信息,请参阅VBScript’s Regular Expression Support上的此页。