string pattern = "\"(?<id>[\\w_]+)\":\"(?<value>[0-9]+)\""; Match match = Regex.Match(s, pattern); while (match.Success) { string id = match.Groups["id"].Value; string value = match.Groups["value"].Value; match = match.NextMatch(); }以上代码可以提取 lz 所需的信息lz 的 id 有很多种,id、player_id 等等,不知道是否是固定种类 如果是固定种类,可以对正则表达式做些修改,提取信息的时候可以更方便些,如以下形式提取: string id = match.Groups["id"].Value; string player_id = match.Groups["player_id"].Value;
string str = File.ReadAllText("D:\\1.txt", Encoding.Default); var idarray = Regex.Matches(str, @"(?is)(?<=""id"":"")\d+(?="")").OfType<Match>().Select(t=>t.Value).ToArray();
string id = Regex.Match(str, @"(?is)(?<=""id"":"")\d+(?="")").Value;
Match match = Regex.Match(s, pattern); while (match.Success)
{
string id = match.Groups["id"].Value;
string value = match.Groups["value"].Value;
match = match.NextMatch();
}以上代码可以提取 lz 所需的信息lz 的 id 有很多种,id、player_id 等等,不知道是否是固定种类
如果是固定种类,可以对正则表达式做些修改,提取信息的时候可以更方便些,如以下形式提取:
string id = match.Groups["id"].Value;
string player_id = match.Groups["player_id"].Value;
var idarray = Regex.Matches(str, @"(?is)(?<=""id"":"")\d+(?="")").OfType<Match>().Select(t=>t.Value).ToArray();