using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string pattern = @"(?:(?#
#json->start)(?:(?#
#array->start)\[\s*(?:(?#
#element-in-array->start)(?:(?#
#object->start){\s*(?:(?:(?#
#key:value->start)(?:(?:(?#
#key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?#
#key:value->end))(?:\s*,\s*(?:(?#
#key:value->start)(?:(?:(?#
#key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?#
#key:value->end)))*)?\s*}(?#
#object->end))|(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end))(?#
#element-in-array->end))(?:\s*,\s*(?:(?#
#element-in-array->start)(?:(?#
#object->start){\s*(?:(?#
#key:value->start)(?:(?:(?#
#key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?#
#key:value->end))(?:\s*,\s*(?:(?#
#key:value->start)(?:(?:(?#
#key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?#
#key:value->end)))*\s*}(?#
#object->end))|(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end))(?#
#element-in-array->end)))*\s*\]|\[\s*\](?#
#array->end))|(?:(?#
#object->start){\s*(?:(?:(?#
#key:value->start)(?:(?:(?#
#key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?#
#key:value->end))(?:\s*,\s*(?:(?#
#key:value->start)(?:(?:(?#
#key->start)""[a-zA-Z_]\w*""(?##key->end))\s*:\s*(?:(?#
#value->start)(?R)|""(?:\\.|[^\\""]*)*""|[+-]?(?:[1-9]\d*|0)(?:\.\d+)?|true|false|null(?#value->end)))(?##key:value->end)))*)?\s*}(?#
#object->end))|(?:(?#
#value->start)""(?:\\.|[^\\""]*)*""|(?<=[,:\s\[])[+-]?(?:[1-9]\d*|0)(?:\.\d+)?(?=[\s,\]}])|true|false|null(?#value->end))(?#
#json->end))";
string input = @"{
""code"": 1,
""re"": [
""B121""
],
""msg"": null,
""e"": null,
""detailMsg"": null,
""point"": ""com.hshc.hshcwap.modules.secondhand.controller.SecondHandController.queryBrand(SecondHandController.java:270)"",
""pointList"": [ ],
""error"": false,
""success"": true,
""successAndReNN"": true
}
-------------
true,false , null, +33.640, 055.23,-22.340, ""12\""a\\\\""
-------------
{}
------------
{
""dt"":""LEADSEC_CS_0700R0600B20171127140643"",
""level"":20,
""id"":""152525881"",
""type"":""Alert Log"",
""time"":1585291269424,
""source"":{
""ip"":""100.100.100.1"",
""port"":50223,
""mac"":""ec-41-18-19-3a-54""
},
""destination"":{
""ip"":""20.20.2.4"",
""port"":80,
""mac"":""c8-0c-c8-ef-09-50""
},
""protocol"":""HTTP"",
""securityid"":""4"",
""attackid"":""1003"",
""subject"":""HTTP_Acunetix11_AWVS11_Content_Web漏洞扫描2"",
""message"":""nic=5;Method=POST;Host=20.20.2.4;URL长度=215;Http协议头长度=875;URL=/cgi-bin/php.cgi?-d allow_url_include=on -d safe_mode=off -d suhosin.simulation=on -d disable_functions=\""\"" -d open_basedir=none -d auto_prepend_file=php:/input -d cgi.force_redirect=0 -d cgi.redirect_status_env=0 -n;访问文件=php.cgi;MsgbodyData=3c 3f 70 68 70 20 65 63 68 6f 28 6d 64 35 28 61 63 75 6e 65 74 69 78 2d 70 68 70 2d 63 67 69 2d 72 63 65 29 29 3b 20 3f 3e;""
}
";
RegexOptions options = RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
{
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx