It seems to me that you just want to
string[] bits = line.Split(new char[] { '\t', ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
(It is assumed that the first column never contains spaces or tabs.)
EDIT: as a regex, you can simply do:
Regex regex = new Regex(@"^[^ \t]+[ \t]+(.*)$");
Code example:
using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { string[] lines = { @"XXXX c:\mypath1\test", @"YYYYYYY c:\this is other path\longer", @"ZZ c:\mypath3\file.txt" }; foreach (string line in lines) { Console.WriteLine(ExtractPathFromLine(line)); } } static readonly Regex PathRegex = new Regex(@"^[^ \t]+[ \t]+(.*)$"); static string ExtractPathFromLine(string line) { Match match = PathRegex.Match(line); if (!match.Success) { throw new ArgumentException("Invalid line"); } return match.Groups[1].Value; } }
source share