VBScript Regexp不会按预期结果

时间:2015-11-27 13:53:47

标签: regex vbscript

Dim regEx
Set regEx = New RegExp
With regEx
    .Pattern = "\[QUOTE=(.*?)\](.*?)\[\/QUOTE\]"
    .IgnoreCase = True
    .Global = True
    .MultiLine = True
End With
string1="[QUOTE=P2]A[/QUOTE]B[QUOTE=P3][QUOTE=P1]C[/QUOTE]D[/QUOTE]E"
response.write regEx.Replace(string1, "")

我希望 BE ,但我得到 BD [/ QUOTE] E

问题出在哪里?

1 个答案:

答案 0 :(得分:0)

只需逐步进行一些转换即可获得必要的结构,然后检索结果:

string1 = "[QUOTE=P2]A[/QUOTE]B[QUOTE=P3][QUOTE=P1]C[/QUOTE]D[/QUOTE]E"
With New RegExp
    .IgnoreCase = True
    .Global = True
    .MultiLine = True
    .Pattern = "\[QUOTE=(.*?)\]"
    string1 = .Replace(string1, "[")
    .Pattern = "\[\/QUOTE\]"
    string1 = .Replace(string1, "]")
    .Pattern = "\[[^[]]*?\]"
    Do While .Test(string1)
        string1 = .Replace(string1, "")
    Loop
End With
response.write string1