简体   繁体   中英

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

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

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

DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM