Csharp/C Sharp by API/System.Text.RegularExpressions/Match — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 15:08, 26 мая 2010
Match.Groups
<source lang="csharp"> using System; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Text.RegularExpressions; using System.Reflection; public class MainClass{
public static void Main(){ Regex r = new Regex(@"<([^>]+)>([^<]*)</(\1)>"); Match m = r.Match("<M>S</M>"); Console.WriteLine("Tag: {0}, InnerText: {1}", m.Groups[1].Value, m.Groups[2].Value); }
}
</source>
Match.Index
<source lang="csharp"> using System; using System.Text.RegularExpressions;
class MatchingApp {
static void Main(string[] args) { Regex r = new Regex("in"); Match m = r.Match("Matching"); if (m.Success) { Console.WriteLine("Found "{0}" at position {1}",m.Value, m.Index); } }
}
</source>
Match.Value
<source lang="csharp"> using System; using System.Text.RegularExpressions;
class MatchingApp {
static void Main(string[] args) { Regex r = new Regex("in"); Match m = r.Match("Matching"); if (m.Success) { Console.WriteLine("Found "{0}" at position {1}",m.Value, m.Index); } }
}
</source>