List<string> srcList=new List<string>();
string pattern="<script[^>]*?src=\"([^>]*?)\"[^>]*?>";
MatchCollection mcs=Regex.Matchs(html,pattern,RegexOptions.IgnoreCase);
foreach(Match m in mcs)
{
srcList.Add(m.Groups[1].Value);
}
十分感谢、
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; }
你好,请问这是怎么回事?
@TheSongOfSoul: 路径需要是一个本地文件路径
@Don'tWorryBeHappy:
@TheSongOfSoul: https://msdn.microsoft.com/zh-cn/library/b49yw9s8(v=vs.110).aspx
可以参考这个链接
(?<=<script src=").*?(?=")