繁体   English   中英

正则表达式如何获取文件路径

[英]Regular expression how to get filepath

我有一个类似的配置文件:

#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

我想通过正则表达式获取时间,文件路径和命令。 我试过了:

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");
  }  

但这是行不通的

您忘记添加模式以匹配空格。

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

DEMO

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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