6

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"
}
2
  • Won't you also get status code 500 Internal Server Error for these screens? Anyway, good luck!
    – Kobi
    Commented Feb 28, 2010 at 11:49
  • @Kobi, Yeah, sure do. thats why I am parsing the page out as it has the actual exception. Nothing I hate worse is a catch all exception message when the information is actually available. Commented Feb 28, 2010 at 11:57

2 Answers 2

4

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).

4
  • thanks. this is one of those late nights where my grasp of the obvious leaked out my ear at around midnight. Commented Feb 28, 2010 at 11:30
  • r.e. CTRL+SHFT+J - yea, i use it quite a bunch. I work on a lot of javascript intellisense code... Commented Feb 28, 2010 at 11:31
  • oops, showing my ignorance again - now I realize you are talking about FF err console. Thanks. Commented Feb 28, 2010 at 11:41
  • No problem, happy to help. Now, take a short break. It's on me :)
    – Kobi
    Commented Feb 28, 2010 at 11:45
2

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

1
  • thanks, mark. you are right, but not trying to replace, just match. Kobi nailed it too. Commented Feb 28, 2010 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.