试过转对象了,这个格式不会定义实体啊!!太复杂了
http://msdn.microsoft.com/zh-cn/library/bb412179.aspx
http://www.cnblogs.com/coderzh/archive/2008/11/25/1340862.html

解决方案 »

  1.   


    明白了,是因为前一个的逗号被匹配,导致后一个少一个逗号了
    那其实改一下正则即可"rect.*?value":"218BE154127B426C96F251D325B09FDA"\}}}
      

  2.   

    第二个正则如下"path[^"]*":\{"from":"rect9c55044f-7312-5704-eacd-14c638f8fbc8",[^\}]*\},
      

  3.   


    明白了,是因为前一个的逗号被匹配,导致后一个少一个逗号了
    那其实改一下正则即可"rect.*?value":"218BE154127B426C96F251D325B09FDA"\}}}这个把整个块都匹配到了。不行诶。如图
      

  4.   

    这样子就Ok啦~~~"rect((?!}}}).)*"218BE154127B426C96F251D325B09FDA"}}}
      

  5.   


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.IO;
    namespace sxLdfang
    {
        class Program
        {
            static void Main(string[] args)
            {
                string html = @"{""states"":{""rect4ba5499a-e27c-fbed-7e0a-6d869466decd"":{""rectId"":""4ba5499a-e27c-fbed-7e0a-6d869466decd"",""type"":""dataAllCity"",""param"":true,""num"":""1"",""pId"":""0"",""dimId"":""0"",""pointTo"":""rect78458cfc-3ddb-b45e-e5c5-0fe47c47ab02"",""descr"":"""",""text"":{""text"":""A""}, ""attr"":{""x"":456, ""y"":18, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""A""}}},""rectad36e8e7-13c5-bddd-6506-949ab53ad464"":{""rectId"":""ad36e8e7-13c5-bddd-6506-949ab53ad464"",""type"":""dataDim"",""param"":true,""num"":""2"",""pId"":""4ba5499a-e27c-fbed-7e0a-6d869466decd"",""dimId"":""218BE154127B426C96F251D325B09FDA"",""pointTo"":""rect9c55044f-7312-5704-eacd-14c638f8fbc8"",""descr"":"""",""text"":{""text"":""B""}, ""attr"":{""x"":262, ""y"":128, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""B""},""itemValue"":{""value"":""218BE154127B426C96F251D325B09FDA""}}},""rect9c55044f-7312-5704-eacd-14c638f8fbc8"":{""rectId"":""9c55044f-7312-5704-eacd-14c638f8fbc8"",""type"":""dataDim"",""param"":true,""num"":""3"",""pId"":""ad36e8e7-13c5-bddd-6506-949ab53ad464"",""dimId"":""E7F7F6554CED46A4AB37A0135CD0BBF6"",""pointTo"":""rect98213e5a-681f-4b2c-4456-a8269d189cd0"",""descr"":"""",""text"":{""text"":""D""}, ""attr"":{""x"":239, ""y"":286, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""C""},""itemValue"":{""value"":""E7F7F6554CED46A4AB37A0135CD0BBF6""}}},""rect44ae9ae5-b2c5-eaed-1892-2dede8217807"":{""rectId"":""44ae9ae5-b2c5-eaed-1892-2dede8217807"",""type"":""dataDim"",""param"":true,""num"":""4"",""pId"":""9c55044f-7312-5704-eacd-14c638f8fbc8"",""dimId"":""218BE154127B426C96F251D325B09FDA"",""pointTo"":"""",""descr"":"""",""text"":{""text"":""D""}, ""attr"":{""x"":158, ""y"":436, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""G""},""itemValue"":{""value"":""218BE154127B426C96F251D325B09FDA""}}},""rect98213e5a-681f-4b2c-4456-a8269d189cd0"":{""rectId"":""98213e5a-681f-4b2c-4456-a8269d189cd0"",""type"":""dataDim"",""param"":true,""num"":""5"",""pId"":""9c55044f-7312-5704-eacd-14c638f8fbc8"",""dimId"":""0C46C65F0FA842F9A08662A1824B971A"",""pointTo"":""recte8830ee9-c88a-f22c-9032-7b725ca01a52"",""descr"":"""",""text"":{""text"":""D""}, ""attr"":{""x"":377, ""y"":420, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""C""},""itemValue"":{""value"":""0C46C65F0FA842F9A08662A1824B971A""}}},""rect78458cfc-3ddb-b45e-e5c5-0fe47c47ab02"":{""rectId"":""78458cfc-3ddb-b45e-e5c5-0fe47c47ab02"",""type"":""dataDim"",""param"":true,""num"":""6"",""pId"":""4ba5499a-e27c-fbed-7e0a-6d869466decd"",""dimId"":""218BE154127B426C96F251D325B09FDA"",""pointTo"":""rect191cbdf9-8245-4e69-096d-8b41e6127d11"",""descr"":"""",""text"":{""text"":""E""}, ""attr"":{""x"":563, ""y"":144, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""D""},""itemValue"":{""value"":""218BE154127B426C96F251D325B09FDA""}}},""rect191cbdf9-8245-4e69-096d-8b41e6127d11"":{""rectId"":""191cbdf9-8245-4e69-096d-8b41e6127d11"",""type"":""dataDim"",""param"":true,""num"":""7"",""pId"":""78458cfc-3ddb-b45e-e5c5-0fe47c47ab02"",""dimId"":""218BE154127B426C96F251D325B09FDA"",""pointTo"":""rectef32f236-361c-35dd-2c08-1a704f5ddb72"",""descr"":"""",""text"":{""text"":""E""}, ""attr"":{""x"":594, ""y"":273, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""D""},""itemValue"":{""value"":""218BE154127B426C96F251D325B09FDA""}}},""rectef32f236-361c-35dd-2c08-1a704f5ddb72"":{""rectId"":""ef32f236-361c-35dd-2c08-1a704f5ddb72"",""type"":""dataDim"",""param"":true,""num"":""8"",""pId"":""191cbdf9-8245-4e69-096d-8b41e6127d11"",""dimId"":""A0B224DC05D04D5DAFF43CC5E9BD5830"",""pointTo"":"""",""descr"":"""",""text"":{""text"":""G""}, ""attr"":{""x"":566, ""y"":422, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""D""},""itemValue"":{""value"":""A0B224DC05D04D5DAFF43CC5E9BD5830""}}},""rect0a1af210-cbfa-5cd7-4c7e-330fe1d666fc"":{""rectId"":""0a1af210-cbfa-5cd7-4c7e-330fe1d666fc"",""type"":""dataDim"",""param"":true,""num"":""9"",""pId"":""98213e5a-681f-4b2c-4456-a8269d189cd0"",""dimId"":""17127F0D4EC34CC7A610B8B4F443F808"",""pointTo"":"""",""descr"":"""",""text"":{""text"":""D""}, ""attr"":{""x"":374, ""y"":554, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""D""},""itemValue"":{""value"":""17127F0D4EC34CC7A610B8B4F443F808""}}},""recte8830ee9-c88a-f22c-9032-7b725ca01a52"":{""rectId"":""e8830ee9-c88a-f22c-9032-7b725ca01a52"",""type"":""dataDim"",""param"":true,""num"":""10"",""pId"":""98213e5a-681f-4b2c-4456-a8269d189cd0"",""dimId"":""3E1968A8AACF48D9891CF2A9D4896B23"",""pointTo"":"""",""descr"":"""",""text"":{""text"":""E""}, ""attr"":{""x"":528, ""y"":546, ""width"":100, ""height"":50}, ""props"":{""text"":{""value"":""D""},""itemValue"":{""value"":""3E1968A8AACF48D9891CF2A9D4896B23""}}}},""paths"":{""pathd355cb2e-053b-0aff-0d29-1049fbb96625"":{""from"":""rect4ba5499a-e27c-fbed-7e0a-6d869466decd"",""to"":""rectad36e8e7-13c5-bddd-6506-949ab53ad464""},""path61975ce7-a9fd-b523-5f5e-53383c857584"":{""from"":""rectad36e8e7-13c5-bddd-6506-949ab53ad464"",""to"":""rect9c55044f-7312-5704-eacd-14c638f8fbc8""},""pathe4c696f9-0ca9-077f-50cc-cf423925601d"":{""from"":""rect9c55044f-7312-5704-eacd-14c638f8fbc8"",""to"":""rect44ae9ae5-b2c5-eaed-1892-2dede8217807""},""path58163c40-1000-0ce2-41fd-d0c9fd155438"":{""from"":""rect9c55044f-7312-5704-eacd-14c638f8fbc8"",""to"":""rect98213e5a-681f-4b2c-4456-a8269d189cd0""},""pathfc957cbb-9884-cac0-bf44-de0077842006"":{""from"":""rect4ba5499a-e27c-fbed-7e0a-6d869466decd"",""to"":""rect78458cfc-3ddb-b45e-e5c5-0fe47c47ab02""},""path90019eba-dc8e-8194-c76a-220dc2fde601"":{""from"":""rect78458cfc-3ddb-b45e-e5c5-0fe47c47ab02"",""to"":""rect191cbdf9-8245-4e69-096d-8b41e6127d11""},""path2ae1f030-e717-6717-74f5-6654fcd157d0"":{""from"":""rect191cbdf9-8245-4e69-096d-8b41e6127d11"",""to"":""rectef32f236-361c-35dd-2c08-1a704f5ddb72""},""path1fb7ce8a-f2c1-fa8a-2880-a06e371887cd"":{""from"":""rect98213e5a-681f-4b2c-4456-a8269d189cd0"",""to"":""rect0a1af210-cbfa-5cd7-4c7e-330fe1d666fc""},""path3681110f-e8ee-4592-031b-6aba64bcc073"":{""from"":""rect98213e5a-681f-4b2c-4456-a8269d189cd0"",""to"":""recte8830ee9-c88a-f22c-9032-7b725ca01a52""}}}";
                string pattern = @"(?<=},\s*)""[^{]+{[^{}]+""rect9c55044f-7312-5704-eacd-14c638f8fbc8""[^{}]+},";
                MatchCollection mc = Regex.Matches(html, pattern);
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Value);
                }
                Console.ReadKey();
            }
        }
    }
    运行结果:
    "pathe4c696f9-0ca9-077f-50cc-cf423925601d":{"from":"rect9c55044f-7312-5704-eacd-14c638f8fbc8","to":"rect44ae9ae5-b2c5-eaed-1892-2dede8217807"},
    "path58163c40-1000-0ce2-41fd-d0c9fd155438":{"from":"rect9c55044f-7312-5704-eacd-14c638f8fbc8","to":"rect98213e5a-681f-4b2c-4456-a8269d189cd0"},
      

  6.   

    。。你好,这个匹配的是 from ,,我这个是要 匹配 to  的内容,已知道
    to=  "rect98213e5a-681f-4b2c-4456-a8269d189cd0"  求所在块
      

  7.   

    。。你好,又碰到一个难题了,,我如果已知  红色  里面的内容,求紫色部分内容
    类似的,把from改成to,后面跟上固定内容即可
      

  8.   


    你把下面这句:
    string pattern = @"(?<=},\s*)""[^{]+{[^{}]+""rect9c55044f-7312-5704-eacd-14c638f8fbc8""[^{}]+},";
    改成:
    string pattern = @"(?<=},\s*)""[^{]+{[^{}]+to=  "”rect98213e5a-681f-4b2c-4456-a8269d189cd0""[^{}]+},";不就行了?
      

  9.   


                MatchCollection mc = Regex.Matches(s, @"""[^,]*?,\s*?""to"":""rect44ae9ae5-b2c5-eaed-1892-2dede8217807[^,]*?,");
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Value);
                }输出:
    "pathe4c696f9-0ca9-077f-50cc-cf423925601d":{"from":"rect9c55044f-7312-5704-eacd-14c638f8fbc8","to":"rect44ae9ae5-b2c5-eaed-1892-2dede8217807"},
      

  10.   

    改一下            MatchCollection mc = Regex.Matches(s, @"""[^,]*?,[^:]*?:""rect44ae9ae5-b2c5-eaed-1892-2dede8217807[^,]*?,");
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Value);
                }
    输出:
    "pathe4c696f9-0ca9-077f-50cc-cf423925601d":{"from":"rect9c55044f-7312-5704-eacd-14c638f8fbc8","to":"rect44ae9ae5-b2c5-eaed-1892-2dede8217807"},
      

  11.   

    最后正则(?<=},\s*)"[^{]+{[^{}]+"to":"rect9c55044f-7312-5704-eacd-14c638f8fbc8"谢谢各位的耐心帮忙
      

  12.   

    最后正则(?<=},\s*)"[^{]+{[^{}]+"to":"rect9c55044f-7312-5704-eacd-14c638f8fbc8""[^,]*?,[^:]*?:"rect44ae9ae5-b2c5-eaed-1892-2dede8217807"[^,]*?,?2个都可以感谢21楼朋友,我也试了下,少了个双引号!,还有尾巴逗号有时候出现在结尾就匹配不到。
    其实我昨天就结贴过了,不知道为何失败,然后期间又发现第二个的问题,所以直接用了。100分太少了。。不好意思