Как показать, какое под-регулярное выражение не соответствует?
Я использую регулярные выражения для проверки ввода пользователя. Следующий код собирает совпадения, доступные с theMatch.Groups ["идентификатор"]. Как я могу получить список подстрок, которые не совпадают в каждой группе?
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace RegExGroup
{
class Test
{
public static void Main( )
{
string string1 = "04:03:27 127.0.0.0 comcom.com";
// group time = one or more digits or colons followed by space
Regex theReg = new Regex( @"(?(\d|\:)+)\s" +
// ip address = one or more digits or dots followed by space
@"(?(\d|\.)+)\s" +
// site = one or more characters
@"(?\S+)" );
// get the collection of matches
MatchCollection theMatches = theReg.Matches( string1 );
// iterate through the collection
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"] );
}
}
}
}
}
поэтому, если пользователь вводит 0xx: 03: 27 127.0.0.0? .com
Я хочу вывести
time: 0xx:03:27
site: ?.com
Кроме того, у кого-нибудь есть хорошие ссылки для использования регулярных выражений в C #?
Спасибо, любая помощь приветствуется.