using System;
using System.Text.RegularExpressions;
class Test
{
public static void Main()
{
string string1 = "04:03:27 127.0.0.0 yourdomain.com";
Regex theReg = new Regex(@"(?<time>(\d|\:)+)\s" +
@"(?<ip>(\d|\.)+)\s" +
@"(?<site>\S+)");
MatchCollection theMatches = theReg.Matches(string1);
foreach (Match theMatch in theMatches)
{
if (theMatch.Length != 0)
{
Console.WriteLine("\ntheMatch: {0}",theMatch.ToString());
Console.WriteLine("time: {0}",theMatch.Groups["time"]);
Console.WriteLine("ip: {0}",theMatch.Groups["ip"]);
Console.WriteLine("site: {0}",theMatch.Groups["site"]);
}
}
}
}
|