{"name":"北京","id":1001},{"name":"长沙","id":1002},{"name":"乌鲁木齐","id":1003}
字符串如上:
以{"name":"北京","id":1001}为一个单位匹配
 北京 1001 部分可变,其他不变,数字长度也可变谢谢!!!

解决方案 »

  1.   

    用C#写:
    using System.Text.RegularExpressions;//code
    string str = "{\"name\":\"北京\",\"id\":1001},{\"name\":\"长沙\",\"id\":1002},{\"name\":\"乌鲁木齐\",\"id\":1003}";
    string pattern = @"{""name"":""(\w+)"",""id"":(\d+)}";
    System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(str, pattern);foreach (Match m in mc)
    {
        Response.Write(string.Format("name:{0}, id:{1}<br />", m.Groups[1].Value, m.Groups[2].Value));
    }