问题描述
我有多个正则表达式匹配,我怎么可以把它们放到一个数组并分别打电话给他们每个例如 ID [0] ID [1]
字符串值=({\\ID \\:\\([A-ZA-Z0-9 _,] +)\\);
字符串ID = Regex.Matches(textt,@value);`
您可以做到这一点已经,因为<一href=\"http://msdn.microsoft.com/en-us/library/system.text.regularex$p$pssions.matchcollection.aspx\"><$c$c>MatchCollection$c$c>有一个<一个href=\"http://msdn.microsoft.com/en-us/library/system.text.regularex$p$pssions.matchcollection.item.aspx\">int索引,让您通过索引来访问比赛。这是完全正确的:
MatchCollection匹配= Regex.Matches(textt,@value);
比赛firstMatch =比赛[0];
但如果你真的想要把比赛放到一个数组,你可以这样做:
匹配[]匹配= Regex.Matches(textt,@value)
.Cast&LT;匹配和GT;()
.ToArray();
I have multiple Regex Matches, how can i put them into an array and call them each individually for example ID[0] ID[1]
string value = ("{\"ID\":\"([A-Za-z0-9_., ]+)\",");
string ID = Regex.Matches(textt, @value);`
You can do that already, since MatchCollection
has an int indexer that lets you access matches by index. This is perfectly valid:
MatchCollection matches = Regex.Matches(textt, @value);
Match firstMatch = matches[0];
But if you really want to put the matches into an array, you can do:
Match[] matches = Regex.Matches(textt, @value)
.Cast<Match>()
.ToArray();
这篇关于我怎样才能把regex.matches到一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!