<script type="text/javascript" src="http://sjs.sinajs.cn/blog7common/js/config.js"></script>
取出src的内容和
<script >
之间的内容
</script>
也就是
有外部链接时取src内容没有就全取出来js

解决方案 »

  1.   

    两个都要
    分不同情况,
    有外联,就取外部js
    没有
    就那段js代码
      

  2.   

    src="(?<url>[^"]*)">(?<text>[^</]+)
      

  3.   

    string str = "<script type=\"text/javascript\" src=\"http://sjs.sinajs.cn/blog7common/js/config.js\">fsdfs</script>";
                Regex reg = new Regex("(?is)((?<=<script[^>]*src=\")[^>]*(?=\"[^>]*>))|(?<=<script[^>]*>).*(?=</script>)");
                string result = "";
                foreach (Match m in reg.Matches(str))
                {
                    if (m.Value == "")
                        continue;
                    else
                    {
                        result = m.Value;
                        break;
                    }
                }
                MessageBox.Show(result);
      

  4.   

    只要src和fsdfs(js内容)
    谢谢了,写好就结贴了
      

  5.   

    C# codestring str = "<script type=\"text/javascript\" src=\"http://sjs.sinajs.cn/blog7common/js/config.js\">fsdfs</script>";
                Regex reg = new Regex("(?is)((?<=<script[^>]*src=\")[^>]*(?=\"[^>]*>))|(?<=<script[^>]*>).*(?=</script>)");
                string result = "";
                foreach (Match m in reg.Matches(str))
                {
                    if (m.Value.Trim() == "")
                        continue;
                    else
                    {
                        result = m.Value;
                        break;
                    }
                }
                MessageBox.Show(result);
    先提取src如果没有src或者sre=""就提取js标记中的内容
      

  6.   

    是从html源码里提取的
    我试了一下,全都出来了
      

  7.   


                string html = "<script type=\"text/javascript\" src=\"http://sjs.sinajs.cn/blog7common/js/config.js\">fsdfs </script><script type=\"text/javascript\" src=\"http://sjs.sinajs.cn/blog7common/js/config.js\">fsdfs </script>";
                Regex r = new Regex("src=\"(?<url>[^\"]*)\">(?<text>[^</]+)");
                MatchCollection mc = r.Matches(html);
                foreach (Match item in mc)
                {
                    Console.WriteLine(item.Groups["url"].Value+"|"+item.Groups["text"].Value);
                }
                Console.ReadLine();
      

  8.   

    src="(?<url>[^"]*)">(?<text>[^</]+)|src="(?<url>[^"]*)">
    正则换成上面这个。。更标准的正则等过客来了给你写把。。不会写。。
      

  9.   

    谢谢你的答复
    但是是是从一个html源码里提取的
    http://blog.sina.com.cn/s/blog_44491d9d0100fed1.html
      

  10.   


    (?is)<script(?:.*?src="(?<url>[^"]*))*[^>]*>(?<info>.*?(?=</script))
    src为路径, info为内容,自己做判断即可
      

  11.   

                string strContent = "<script type=\"text/javascript\" src=\"http://sjs.sinajs.cn/blog7common/js/config.js\">fsdfs </script><script type=\"text/javascript\" src=\"http://sjs.sinajs.cn/blog7common/js/config.js\">fsdfs </script>";            Regex reg = new Regex(@"(?is)<script.*?src=""(?<src>[^""]+).*?"">(?<value>.*?)</script>");
                
                Console.WriteLine("/*\n------输出结果------------");
                MatchCollection mc = reg.Matches(strContent);
                foreach (Match m in mc)
                {
                    Console.WriteLine(m.Groups["src"].ToString()+ m.Groups["value"].ToString().PadLeft(20));
                }
                /*
                ------输出结果------------
                http://sjs.sinajs.cn/blog7common/js/config.js              fsdfs
                http://sjs.sinajs.cn/blog7common/js/config.js              fsdfs
                */
      

  12.   

    不好意思说错了,是url和info代码如下:string strContent = @"<script type=""text/javascript"" src=""http://sjs.sinajs.cn/blog7common/js/config.js""> </script> ";
                    Regex re = new Regex("(?is)<script(?:.*?src=\"(?<url>[^\"]*))*[^>]*>(?<info>.*?(?=</script))");
                    string strSrc = "";
                    string strInfo = "";
                    if (re.IsMatch(strContent))
                    {
                        Match m = re.Match(strContent) ;
                        strSrc = m.Groups["url"].Value.Trim();
                        strInfo = m.Groups["info"].Value.Trim();
                    }
      

  13.   

    Regex reg = new Regex("(?is)((?<=.*<script[^>]*src=\").*?(?=\"[^>]*>)|(?<=<script[^>]*>).*?(?=</script>))");
                foreach (Match m in reg.Matches(str))
                {
                    Console.WriteLine(m.Value);
                }
                Console.Read();