views:

280

answers:

2

I built up this regex at http://regextester.com to parse YSOD but VS is complaining about a syntax error. I am sure I am missing an escape somewhere but I am coming up blank.

Here is is in original form. any help is appreciated.

var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs;

UPDATE: Kobi pointed out the obvious and got me moving again. For those who are interested, this is valid JavaScript to test and parse an XMLHttpRequest.responseText for an ASP.net Yellow Screen Of Death (YSOD).

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 - This is the result and the reason I want to parse the html even though I get a 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"
}
+3  A: 

Firefox says:

Error: invalid regular expression flag s
Source Code:
var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs; 

After removing the s it seems ok (of course, it isn't tested, just parsed correctly).

Kobi
For the record: Ctrl+Shift+J gives the error console.
Kobi
thanks. this is one of those late nights where my grasp of the obvious leaked out my ear at around midnight.
Sky Sanders
@Kobi - r.e. CTRL+SHFT+J - yea, i use it quite a bunch. I work on a lot of javascript intellisense code...
Sky Sanders
@Kobi - oops, showing my ignorance again - now I realize you are talking about FF err console. Thanks.
Sky Sanders
No problem, happy to help. Now, take a short break. It's on me :)
Kobi
+2  A: 

The flag s is invalid in Javascript. To replace, use the replace method.

Mark Byers
thanks, mark. you are right, but not trying to replace, just match. Kobi nailed it too.
Sky Sanders