C#匹配标签正则,获取标签的值

比如要获取:

<color=#50cccc>头盔坐标:(-0.6, 1.0, 1.2)</color>
<color=#3d85c6>头盔方向(-0.2, 0.1, 0.1, 1.0)</color>

这样两个标签之间的值:头盔坐标:(-0.6, 1.0, 1.2)、头盔方向(-0.2, 0.1, 0.1, 1.0)

用C#实现:

 1 string[] lines = File.ReadAllLines(@"C:\Users\xxxx\AppData\Local\Unity\Editor\Editor.log");
 2 
 3             List<string> listPos = new List<string>();
 4             foreach(var readLogsPos in lines)
 5             {
 6                 foreach(Match m in Regex.Matches(readLogsPos, @"\<color=#50cccc\>(.*?)\</color\>"))
 7                 {
 8                     listPos.Add(m.Groups[1].Value);
 9                 }
10             }
11             List<string> listRot = new List<string>();
12             foreach(var readLogsRot in lines)
13             {
14                 foreach (Match m in Regex.Matches(readLogsRot, @"\<color=#3d85c6\>(.*?)\</color\>"))
15                 {
16                     listRot.Add(m.Groups[1].Value);
17                 }
18             }

 

posted @ 2017-06-04 21:14  苏景末  阅读(868)  评论(0)    收藏  举报