如字符串为
<script>;lfjas..............函数名(afjka;kjf'....)</script>怎样获取<script>中的内容,怎样获取函数名()中的内容我用string.split("<script>".tochararray())不能获取需要的内容,请问该怎么做?

解决方案 »

  1.   


            string str = "...............";
            string result = "";
            Match m = Regex.Match(str, "(?i)<script>.*?</script>");
            if (m.Success)
                result = m.Value;
      

  2.   

    如果有很多<script>代码段,我只想匹配第二个,该怎么做呢
      

  3.   

            string str = "...............";
            string result = "";
            MatchCollection mc = Regex.Matches(str, "(?i)<script>.*?</script>");
            if(mc.Count>1)
                result = mc[1].Value;
      

  4.   


    笔误把,应该是 if(mc.Count>2) result = mc[1].Value;
      

  5.   

            string str = ".........";
            MatchCollection mc = Regex.Matches(str, @"(?is)function\s+([^\(]+)\(([^\)]+)\)");
            for (int i = 0; i < mc.Count; i++)
            {
                string fName = mc[i].Groups[1].Value;//函数名
                string fCloumns = mc[i].Groups[2].Value;//函数字段内容
            }
      

  6.   

    (?i) 不区分大小写
    (?is) 不区分大小写 + 单行模式