首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-01-29 
求正则表达式,从Aspx页面中读取校验控件asp:RegularExpressionValidatorid revEMail runat server

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

热点排行