我必须解析一个构建日志文件并找到在导出我的工作沙箱时丢失的一些头文件。在C++中,我设法解决了这个问题,但同样的模式对C#无效。
下面是我要解析的行,以获得丢失的头文件的名称:
"Src/EBS\FSW/CustSW/CustSW_generic/RSC/Src/gen/rsc_iohandling_types.h", 第1行:错误(dcc:1621):无法找到包含文件FSW/CustSW/CustSW_plugin/RSC_plugin/RSC_Volvo_QC1/Src/gen/rsc_interfacestructures_types.h "out/VOLVO/QC1/gen/Src/EBS\FSW/CustSW/CustSW_plugin/RSC_plugin/RSC_Volvo_QC1/Src/gen/rsc_b_interfacestructures_types.h", 第19行:错误(dcc:1621):无法找到包含文件FSW/CustSW/CustSW_generic/RSC/Src/gen/rsc_cpif.h "out/VOLVO/QC1/gen/Src/EBS\FSW/CustSW/CustSW_generic/RSC/Src/gen/tvc_safe_types.h", 第19行:错误(dcc:1621):无法找到包含文件FSW/CustSW/CustSW_generic/RSC/Src/gen/rsc_cpif.h "Src/EBS\FSW/CustSW/CustSW_generic/RSC/Src/gen/rsc_iohandling_types.h", 第3行:错误(dcc:1621):找不到包含文件rsc_qm_interfacestructures_types.h
这是当前错误的代码:
string[] errLns = System.IO.File.ReadAllLines(logFilePath);
List<string> hdrFiles = new List<string>();
string rgxPat = @"can't find include (\w+/)*(\w+\.[hed|he|hdb|h])";
Regex incLRgx = new Regex(rgxPat, RegexOptions.IgnoreCase);
foreach (string actLine in errLns)
{
Match match = incLRgx.Match(actLine);
hdrFiles.Add(match.Groups[2].Value);
}我只想拥有没有相对路径的文件名。
发布于 2019-07-30 09:58:43
你可以用
\bcan't\s+find\s+include\s+file\s+(?:\w+/)*(\w+\.(?:hed?|hdb|h))\b抓住第一组。见这个regex演示。
详细信息
\b -字边界can't\s+find\s+include\s+file\s+ - can't find include file,在单词之间和后面加上1+空格(?:\w+/)* - 0+出现的1+单词字符与/后面(\w+\.(?:hed?|hdb|h)) -第1组: 1+ word chars,.,然后是he,hed,hbd或h\b -词边界。C#代码:
string errLns = System.IO.File.ReadAllText(logFilePath);
List<string> hdrFiles = new List<string>();
string rgxPat = @"\bcan't\s+find\s+include\s+file\s+(?:\w+\/)*(\w+\.(?:hed?|hdb|h))\b";
Regex incLRgx = new Regex(rgxPat, RegexOptions.IgnoreCase);
hdrFiles.AddRange(incLRgx.Matches(errLns).Cast<Match>().Select(x => x.Groups[1].Value).ToArray());发布于 2019-07-30 10:09:51
试试这个模式can't find include file .+\.(?=hed|he|hdb|h)
can't find include file -匹配can't find include file字面意思
.+ -匹配任何字符中的一个或多个
\. =匹配.字面意思
(?=hed|he|hdb|h) -积极展望-断言下面的是hed,he,hdb或h中的一个
https://stackoverflow.com/questions/57268931
复制相似问题