首页 > 代码库 > C# 正则匹配路径和文件名

C# 正则匹配路径和文件名

private static void getPathAndFilename(String logFolder)
{
string img = "C:\\Users\\jiawang\\Perforce\\EASAP\\jiawang_EASHDPDESK257_6678\nucleus\\SANDBOX\\henryzhu\\ProductAPIValidator\\ProductAPIValidator\\bin\\Debug\\log_info.log";
string regex2 = @"^(?<fpath>([a-zA-Z]:\\)([\s\.\-\w]+\\)*)(?<fname>[\w]+.[\w]+)";

System.Text.RegularExpressions.Match result = System.Text.RegularExpressions.Regex.Match(img, regex2);

if (result.Success)
{
Console.WriteLine("[Full]:" + result.Value);
Console.WriteLine("[Part1]:" + result.Result("${fpath}"));
Console.WriteLine("[Part2]:" + result.Result("${fname}"));

}
Console.ReadLine();

}

C# 正则匹配路径和文件名