zt9788
zt9788

Reputation: 958

Regular expression how to get filepath

I have a config file like:

#time(Second or HH:ss:mm)  exepath
5 c:\windows\notepad 
18:38:00   c:\windows\notepad.exe
18:38:00   "c:\path\path path2\program.exe" command

I want to get time ,filepath and command by regex. I tried:

string line = "18:38:00   c:\windows\notepad.exe.....";//from config file
string reg = @"(\S*)("")?(.*)("")?";

Regex regex = new Regex(reg, RegexOptions.IgnoreCase);
Match m = regex.Match(str);

 if(m.Success)
  {
      Console.Write(" {0} ", m.Groups[1]);
      Console.Write(" {0} ", m.Groups[2]);
      Console.Write("/n");
  }  

but that is not work

Upvotes: 0

Views: 61

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174706

You forget to add the pattern to match in-between space.

@"(?m)^(\S*)\s*""?([^""\n]*)""? *(.*)?$"

DEMO

Upvotes: 1

Related Questions