我在http://regextester.com建立了这个正则表达式来解析YSOD,但是VS抱怨语法错误。我确信我错过了某个地方的逃生,但我空白了。
这是原始形式。任何帮助表示赞赏。
var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs;
更新 科比指出了显而易见的事情,让我再次感动。对于那些感兴趣的人,这是一个有效的JavaScript来测试和解析ASP.net黄色死亡屏幕(YSOD)的XMLHttpRequest.responseText。
var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*[\n\r]*)*?)\s*(at(.*[\n\r]*)*)-->/;
if (rxYSOD.test(text)) {
// looks like one..
var ysod = rxYSOD.exec(text);
errObj = { Message: ysod[2], StackTrace: ysod[4], ExceptionType: ysod[1] };
}
@Kobi - 这是结果以及我想解析html的原因,即使我得到500:
{
"message": " Unknown web method ValidateUser.\r\nParameter name: methodName\r\n",
"stackTrace": "at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)\r\n at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)\r\n at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)\r\n at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)\r\n at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n",
"exceptionType": "ArgumentException",
"errorObject": {
"Message": " Unknown web method ValidateUser.\r\nParameter name: methodName\r\n",
"StackTrace": "at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)\r\n at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)\r\n at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)\r\n at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)\r\n at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n",
"ExceptionType": "ArgumentException"
},
"statusCode": 500,
"servicePath": "/Authentication_JSON_AppService.axd",
"useGet": false,
"params": {
"username": "testingUser",
"password": "testingUser",
"customCredential": null
},
"methodName": "ValidateUser",
"__typeName": "Salient.ScriptModel.WebServiceError"
}
答案 0 :(得分:4)
Firefox说:
Error: invalid regular expression flag s
Source Code:
var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs;
删除s
后似乎没问题(当然,它没有经过测试,只是正确解析)。
答案 1 :(得分:2)
标记s
在Javascript中无效。要替换,请使用replace
方法。