C# wyrażenia regularne

0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace regular_expressions
{
    class Program
    {
        static void Main(string[] args)
        {
            string string1 = "04:03:27 Jesse 192.168.0.2 Liberty";
            Regex theReg = new Regex(@"(?<time>(\d|\:)+)\s" + @"(?<company>\S+)\s" + @"(?<ip>(\d|\.)+)\s" + @"(?<company>\S+)\s");
            MatchCollection theMatches = theReg.Matches(string1);
            foreach (Match theMatch in theMatches)
            {
                if (theMatch.Length != 0)
                {
                    Console.WriteLine("the Match: {0}", theMatch.ToString());
                    Console.WriteLine("time: {0}", theMatch.Groups["time"]);
                    Console.WriteLine("ip: {0}", theMatch.Groups["ip"]);
                    Console.WriteLine("company: {0}", theMatch.Groups["company"]);

                    foreach(Capture cap in theMatch.Groups["company"].Captures)
                    {
                        Console.WriteLine("cap: {0}",cap.ToString());
                    }
                }
            }
            Console.ReadKey();
        }
    }
}

Dlaczego powyższy kod z wyrażeniami regularnymi nie działa i mi nic nie wyświetla? Jak sprawdzam w debugerze obiekt theMatches to w polu Results view pokazuje "Wyliczenie nie dalo wynikow".

2

Sprawdź jakimś online testerem czy Twój regexp na pewno jest dobry.

0

Prawdopodobnie jest bledny tylko nie widze co jest źle w moim regexie.

2

W regexpie na końcu masz spację.

0

@TomRiddle: Faktycznie. Dzięki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1