.求写个正则,十分感谢。如何获取JS脚本文件的路径
2 回答
湖上湖
TA贡献2003条经验 获得超2个赞
List<string> GetJsFiles(string htmlPath)
{
List<string> jsFiles = new List<string>(); string spacePattern = @"\s*"; string srcPattern = string.Format("src{0}={0}\"(?<srcPath>[^\"]*)\"", spacePattern); string scriptPattern = string.Format(@"\<script[^\>]*{0}[^\>]*\>", srcPattern); string htmlContent = File.ReadAllText(htmlPath);
MatchCollection ms = Regex.Matches(htmlContent, scriptPattern, RegexOptions.IgnoreCase); if (ms.Count > 0)
{ for (int i = 0; i < ms.Count; i++)
{ if (ms[i].Success)
{ string srcPath = ms[i].Groups["srcPath"].Value;
jsFiles.Add(srcPath);
}
}
} return jsFiles;
}- 2 回答
- 0 关注
- 1024 浏览
添加回答
举报
0/150
提交
取消
