当前位置: 代码迷 >> ASP.NET >> 求正则表达式,从Aspx页面中读取校验控件解决思路
  详细解决方案

求正则表达式,从Aspx页面中读取校验控件解决思路

热度:319   发布时间:2013-02-25 00:00:00.0
求正则表达式,从Aspx页面中读取校验控件
<asp:RegularExpressionValidator   id= "revEMail "   runat= "server "   ErrorMessage= "Email   Format   is   wrong "   ControlToValidate= "tbEmail "   ValidationExpression= " <> "   Display= "Dynamic "> </asp:RegularExpressionValidator>


//上边校验控件包含特殊字符,如 <>

------解决方案--------------------------------------------------------
你要读取什么?里面的属性等等?

string s = "。。。。。。。 ";

Regex re = new Regex(@ " <(? <tag> [^\s> ]+)(\s*(? <name> [^=]+)=( " "(? <value> [^ " "]*) " "| '(? <value> [^ ']*) '|(? <value> [^\s> ]*)))*(? <remains> [^> ]*)> (? <inner> .*?) </\k <tag> > ",RegexOptions.Singleline);

Match m = re.Match(s);

if (m.Success)
{
Console.WriteLine( "tag:{0} ", m.Groups[ "tag "].Value);
for(int i=0; i < m.Groups[ "name "].Captures.Count; i++)
Console.WriteLine( "{0}={1} ",m.Groups[ "name "].Captures[i].Value, m.Groups[ "value "].Captures[i].Value);

Console.WriteLine( "remains:{0} ", m.Groups[ "remains "].Value);
Console.WriteLine( "inner:{0} ", m.Groups[ "inner "].Value);
}
else
Console.WriteLine( "no match ");
  相关解决方案