<li> ${username}$ ${userpwd}$ </li>
怎么得到 ${    和    }$ 之间的内容??

解决方案 »

  1.   

    Regex reg = new Regex(@"<book>(.*?)</book>", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                MatchCollection matches = reg.Matches(字符串名称);
                foreach (Match match in matches)
                {
                    book.Cart = "<book>" + match.Groups[1].Value + "</book>";
                }
      

  2.   

            string test = "<li> ${username}$ ${userpwd}$  </li> ";
            MatchCollection mc = Regex.Matches(test, @"(?<=\$\{)[^}]*(?=}\$)");
            foreach (Match m in mc)
            {
                Response.Write(m.Value + "<br>");
            }
      

  3.   

    同楼上,不过正则表达式可以再简化一下       MatchCollection mc = Regex.Matches(test, @"(?<=\$\{)[^}]*");//针对大刮号一定会成对出现的情况       //或者有下式
           MatchCollection mc = Regex.Matches(test, @"(?<=\$\{).*?(?=}\$)"");/