日期:2014-05-18  浏览次数:20566 次

求正则表达式,从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 ");