简体   繁体   中英

How to use extra quotations in a regex statement in c#

Below I have a regex statement I have been working on for quite awhile. The problem I am having is that their are a lot of quotations I am trying to parse out (I think that's the terminology I am looking for) so Visual Studio is freaking out about it. I have tried to fix this using escape characters, but it still won't recognize the whole phrase.

Here is the phrase without the escape characters:

string exceptionPattern = @"(?:(?:"([^"}]*)")|(\w+))\s*:\s*(?:(?:"([^"}]*)")|(\w+))";

With just this code in, nothing else, almost every line in my code gets affected. Here is the code using escape characters:

string exceptionPattern = @"(?:(?:\"([^\"}]*)\")|(\w+))\s*:\s*(?:(?:\"([^\"}]*)\")|(\w+))";

Once this comes into play, only this line is not working. In VS, the ([^\\ part close to the beginning is not highlighted, meaning that it is not in quotes. Does anyone have any idea on how I can fix this problem?

This is the string I am trying to match. Note: THIS IS NOT JSON! I have confirmed it many times with the developer who made the database where this sample is coming from and he confirmed it is not JSON, so please do not try to use JSON on this. Also, the regex I have is trying to match displayException and the message after it, and also exception and the message after that including success false, using the quotes as a point of splitting

{"data":"","displayException":"Invalid Account Status.  Please complete the registration process by clicking the verification link in your eTTek Dash Registration Verification email.  Please contact 1-800-341-6184 M-F 9a-5pm CT for further assistance.","exception":"UNABLE TO LOGIN","success":false}

Inside a verbatim string, to escape a double quotes you must need to add another double double quotes near to that like "" . So the compiler treats "" as a double quotes or otherwise it would treat " as an end of the verbatim string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM