1
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace RegExCs
{
class Program
{
static void Main(string[] args)
{
string rawData;
Regex filter = new Regex(@"(?<ip>([0-9]+\.){3}[0-9])"[email protected]"(?<time>(\s[0-2][0-9]:[0-9][0-9]))");
rawData=File.ReadAllText("Query list");
MatchCollection theMatches = filter.Matches(rawData);
foreach (Match theMatch in theMatches)
{
Console.WriteLine("ip: {0}\n",theMatch.Groups["ip"]);
Console.WriteLine("time: {0}\n", theMatch.Groups["time"]);
}
Console.ReadKey();
}
}
}
“查询列表”文件:两个正则表达式组
Reply from 212.77.100.101 www.wp.pl time: 21:37 Reply from 111.41.130.55 www.cnn.com time: 05:33 Reply from 230.77.100.101 www.piting.com time: 04:12 Reply from 65.77.100.101 www.ha.org time: 12:55 Reply from 200.77.100.101 www.example.com time: 07:56
这个程序编译和运行,但开空控制台窗口的全部时间。为什么?