用于ajax过滤器的正则表达式过滤器

时间:2011-08-03 03:29:55

标签: asp.net ajax regex

我正在尝试为ajax请求编写响应过滤器。具体而言,我正在将.axd调用缩减为一个缓存的脚本调用。我需要一个正则表达式,它将返回所有匹配| 123 | scriptBlock | ScriptPath | ScriptResource.axd?d = blah

以下是我需要匹配的文本示例。最终我需要用空字符串替换所有这些匹配...所以如果我能在一次拍摄中做到这一点就会很棒。

Content_ContentPlaceHolderMain_rwSaveSearch_C_RequiredFieldValidator1" )| 202 |脚本块|了ScriptPath | /MyApp/MyPage/ScriptResource.axd d = 8cuS6HlvJsa1x3tLEcL_TItpBXYm_zmbMr_ctbJmVoYz9JL8P-kaT5M-TlE6yK7pBgANX9zpol_idS8Sj0IaHQ4lC3WfqbZf5Ejr2iWPHH49w-ynh0s-MDLkl3mO8sXuBUHVXEq9Pc5Tv6TRLCyrxy-Qcew1&安培;ΔT= 22cb5c6c | 181 |脚本块|了ScriptPath | / MyApp的/我的页面?/ScriptResource.axd d = ntY1JbINTRtcX6DAOm-LUY-o905uosY8Zpy3si1TvH0FdGOGq83-DclzMqazpnh5uHaBK7NlSAMFP9188wUDQKtolKOvgZpY544PewcHdf8qZQV5KXhWiTI1Ee6xcV99Q8xkJQ2& T公司= 55d87db2 | 202 |脚本块|了ScriptPath | /MyApp/MyPage/ScriptResource.axd d = B1rz4Fn_O0PKVtdTw68GtiU3bFInY6NFO6aVyAeiMqR5JNa5BexYHVOr2TF0gw_p8sZ8SojGciziipec-Y1dEnpkgv0WNksL2i4_P7ZsnSW-AASVlf-Y1ncJY8AriWp2YfQI6lF-Y0w2zD2ocgRxDrN28581&安培;ΔT= 55d87db2 | ?202 |脚本块|了ScriptPath | /MyApp/MyPage/ScriptResource.axd d = Z-wyUCLB7-3WWtK8B2CDVjANFI3YIJe7etu1AsYU5rvwOMmf0zGGkucBfWQiWlBl56QQ8jtOiCllNVEQO9pzFKUdhRtpdAiQSS6OWxqkif0eK1MBY2QhTeSLVjpBlbOu77_jzmLL_Axr-9o6C8pHEtXYnrg1& T公司= 55d87db2 | 223 |脚本?块|了ScriptPath | /MyApp/MyPage/ScriptResource.axd d = _YcNfgF_vWrrR_oicNIXksyqwgv6MBkdHBRWhVOwy-PLmpBMW5DpFQZL6KI8kFkHWY6WnpstMKuOHGETC1y6WzKmSAXOHqaj5GkKmYoiKCXb3qTR_MbDpWdDXmnnlBmSI6b1nLiVAl1XCQD9LOkYQKVvkVHnnAEuxg98HHQ5EwcYxVbQ0&安培;ΔT= 55d87db2 | 202 |脚本块|了ScriptPath | /MyApp/MyPage/ScriptResource.axd d = dQRBFe2100Glspd6HHb7vVm05awW9jeer-UK_UFuuTd3FCAEDsRItcEZTZE7_DJwiSyXp5JRbGT3QvNIsWJEPOOL76SiIM4CP827HsdclJhADXKTxDkKa__xneVcnb3uPptO4EoWNkUaOOQEiORd3dPW2401& T公司= 55d87db2 | 62 | scriptStartupBlock | ScriptContentNoTags | if(typeof)blah ...

1 个答案:

答案 0 :(得分:0)

这种模式应该有效:

\|\d{3}\|scriptBlock\|ScriptPath\|/MyApp/MyPage/ScriptResource\.axd\?d=[^|]*

在C#中,替换代码为:

string pattern = @"\|\d{3}\|scriptBlock\|ScriptPath\|[^|]*ScriptResource\.axd\?d=[^|]*";
string replacement = Regex.Replace(input, pattern, "");

应用于上述字符串,返回

Content_ContentPlaceHolderMain_rwSaveSearch_C_RequiredFieldValidator1")