.求寫個正則,十分感謝。如何獲取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 關注
- 979 瀏覽
添加回答
舉報
0/150
提交
取消
