Home > other >  Regex match for colon separated string with double quotes and GUID using C#
Regex match for colon separated string with double quotes and GUID using C#

Time:07-14

I am trying to find a regex match for possible app IDs such as:

"AppId": "12764ddf-2746-4293-8f63-b79fdc913dca"
"appid": "12764ddf-2746-4293-8f63-b79fdc913dca"

Currently, my regex looks like this, but the quotation marks around app ID are giving compilation errors. I also tried using \", but that also does not work:

Regex appIdRegex = new Regex(@"("appid")"(\s*):(\s*)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$",
                RegexOptions.IgnoreCase);

CodePudding user response:

using @ string, you need to escape " using "".

Regex appIdRegex = new Regex(@"\""appid\""\s*:\s*\""([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\""$", RegexOptions.IgnoreCase);
  • Related