字符串里有<%=str1%>111<%=str2%>这样的内容。 现在要处理字符串,获取每个<%%>中间的值。
求一个new System.Text.RegularExpressions.Regex(@"<(\w+)>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);替换红色部分可以用的正则表达式,多谢!

解决方案 »

  1.   

    Regex a= new Regex("<%=(?<value>.*)%>");
    MatchCollection b= a.Matches("<%=str1%>111<%=str2%>");
    然后循环<%=str1%>和<%=str2%>,每次循环获取想要的值:
    for (int i = 0; i < b.Count; i++) { 
    string value= b[i].Groups["value"].Value;}
    应该是这样的,未经测试
      

  2.   

    (?<=<%=).*?[^%](?=%>)我觉得你可以把=也去掉
    获取每个<%=%>中间的值
      

  3.   

    经测试,可用。
    结果是获取到了=str1, =str2
    如果我想取到<%=str1%>, <%=str2%>
    要如何改呢?
      

  4.   

    3楼代码提取到的数据是
    =str1
    =str2不知你想要什么样的数据?
      

  5.   

    <%=str1%>111<%=str2%>是要获取111还是=str1
      

  6.   

    <%=(\w)+%>
    能取到<%=str1%> 和 <%=str2%>(?<=<%=).*?[^%](?=%>)
    能取到 str1  str2
      

  7.   

    正则式:"<%(\w+)%>" 正则表达式用来验证。对于字符串,假设str=<%=str1%>,用str.Substring(str.IndexOf("<%"),str.LastIndexOf("<%"))获取<%%>中的内容。