Como mostrar qual sub-regex não conseguiu corresponder?
Eu estou usando expressões regulares para validar a entrada do usuário. O código a seguir coleta as correspondências acessíveis com oMatch.Groups ["identifier"]. Como posso obter uma lista de subcordas que não correspondem em cada grupo?
#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( @"(?<time>(\d|\:)+)\s" +
// ip address = one or more digits or dots followed by space
@"(?<ip>(\d|\.)+)\s" +
// site = one or more characters
@"(?<site>\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"] );
}
}
}
}
}
então se o usuário insere 0xx: 03: 27 127.0.0.0? .com
Eu quero saída
time: 0xx:03:27
site: ?.com
Além disso, alguém tem boas referências para usar regexs em c #?
Obrigado, qualquer ajuda apreciada.