日期:2014-05-17 浏览次数:20999 次
string src = "*>2172.16.12.0/24 10.16.12.1 " //匹配
string src = "*>9172.165.125.0/24 10.16.12.1 " //不要匹配
protected void Page_Load(object sender, EventArgs e)
{
string strfortest = @"*>r172.12.12.12/24 10.16.12.1
*> 172.16.12.0/2 10.16.12.1
*> 172.16.12.0/ 10.16.12.1
*> 172.16.12.0/ 10.16.12.1
*> 172.1.1.666/2 10.16.12.1
*> 172.1.1.77/2 10.16.12.1
*> 172.16.12.8/2 10.16.12.1
*> 172.16.12.90/2 10.16.12.1 ";
string[] strforcheck = { "16", "12", "34" };
MatchCollection mc = Regex.Matches(strfortest, @"\*\>[\w\W]+?\.(\d+)\.(\d+)\.(\d+)/\d+[^*]+");
List<string> list = new List<string>();
foreach (Match match in mc)
{
for (int i = 1; i <= match.Groups.Count; i++)
{
Boolean boolean = false;
for (int j = 0; j < strforcheck.Length; j++)
{
if (match.Groups[i].Value.Equals(strforcheck[j]))
{
list.Add(match.Value);