CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

又是正则表达式

楼主shixueli(我们总是不能随心所欲)2003-08-02 02:21:13 在 .NET技术 / ASP.NET 提问

我想匹配<table   width="100%"   height=""   border="0"   style=""    
  cellpadding="0"   cellspacing="0">  
  这里面的每一个属性都是可省的,应该怎么写啊? 问题点数:100、回复次数:6Top

1 楼saucer(思归)回复于 2003-08-02 02:25:40 得分 0

if   you   don't   need   to   match   those   attributes,   you   can   do  
   
  <table[^>]*>  
  Top

2 楼shixueli(我们总是不能随心所欲)回复于 2003-08-02 02:33:24 得分 0

to   saucer(思归,   MS   .NET   MVP):  
  我是想  
  除了我上面写的属性之外,如果再有别的东西,比如onclick我是不会匹配的,  
  怎么办,你的方法连onclik都匹配了Top

3 楼shixueli(我们总是不能随心所欲)回复于 2003-08-02 02:44:07 得分 0

帮帮忙吧,本人的另外一个贴的分也可以给他:  
  http://expert.csdn.net/Expert/topic/2097/2097696.xml?temp=.5310938  
   
  同一个问题Top

4 楼saucer(思归)回复于 2003-08-02 02:52:41 得分 100

if   you   want   to   match   everything,   try  
   
   
  string[]   slist   =   {"<table   width=\"100%\"   height=\"\"   border=\"0\"   style=\"\"   cellpadding=\"0\"   cellspacing=\"0\">",  
  "<table>","<table   border=\"1\"     >",   "<table   border=\"1\"   width=\"100%\"     test=\"ss\"   >",  
  "<table   test=\"ss\"   border=\"1\"   width=\"100%\"       >"  
  }  
  ;  
  Regex   re   =   new   Regex(@"<table(?:[^>]*?(?:width=""(?<width>[^""]*)""|height=""(?<height>[^""]*)""|border=""(?<border>[^""]*)""|style=""(?<style>[^""]*)""|cellpadding=""(?<cellpadding>[^""]*)""|cellspacing=""(?<cellspacing>[^""]*)""))*[^>]*?>",    
   
  RegexOptions.IgnoreCase   |   RegexOptions.Singleline);  
  foreach   (string   s   in   slist)  
  {  
    Console.WriteLine("\nfor:\t{0}\n",s);  
  Match   m     =   re.Match(s);  
  if   (m.Success)  
  {  
    Console.WriteLine("width:{0}",m.Groups["width"].Value);  
    Console.WriteLine("height:{0}",m.Groups["height"].Value);  
    Console.WriteLine("border:{0}",m.Groups["border"].Value);  
    Console.WriteLine("style:{0}",m.Groups["style"].Value);  
    Console.WriteLine("cellpadding:{0}",m.Groups["cellpadding"].Value);  
    Console.WriteLine("cellspacing:{0}",m.Groups["cellspacing"].Value);  
   
  }  
  }  
   
   
  if   you   just   want   what   you   listed   it,   try  
  string[]   slist   =   {"<table   width=\"100%\"   height=\"\"   border=\"0\"   style=\"\"   cellpadding=\"0\"   cellspacing=\"0\">",  
  "<table>","<table   border=\"1\"     >",   "<table   border=\"1\"   width=\"100%\"     test=\"ss\"   >",  
  "<table   test=\"ss\"   border=\"1\"   width=\"100%\"       >"  
  }  
  ;  
  Regex   re   =   new   Regex(@"<table(?:\s*(?:width=""(?<width>[^""]*)""|height=""(?<height>[^""]*)""|border=""(?<border>[^""]*)""|style=""(?<style>[^""]*)""|cellpadding=""(?<cellpadding>[^""]*)""|cellspacing=""(?<cellspacing>[^""]*)""))*\s*>",   RegexOptions.IgnoreCase   |   RegexOptions.Singleline);  
  foreach   (string   s   in   slist)  
  {  
    Console.WriteLine("\nfor:\t{0}\n",s);  
  Match   m     =   re.Match(s);  
  if   (m.Success)  
  {  
    Console.WriteLine("width:{0}",m.Groups["width"].Value);  
    Console.WriteLine("height:{0}",m.Groups["height"].Value);  
    Console.WriteLine("border:{0}",m.Groups["border"].Value);  
    Console.WriteLine("style:{0}",m.Groups["style"].Value);  
    Console.WriteLine("cellpadding:{0}",m.Groups["cellpadding"].Value);  
    Console.WriteLine("cellspacing:{0}",m.Groups["cellspacing"].Value);  
   
  }  
  }Top

5 楼shixueli(我们总是不能随心所欲)回复于 2003-08-02 02:55:51 得分 0

试试Top

6 楼shixueli(我们总是不能随心所欲)回复于 2003-08-02 03:13:58 得分 0

好用,谢谢思归大哥!Top

相关问题

  • TO: keiy 又是关于那个正则表达式的问题。急!!
  • 又是正则表达式!关于TextBox的
  • 还是正则表达式
  • 还是正则表达式
  • 也是关于正则表达式的
  • 请问什么是正则表达式?
  • 什么是正则表达式?
  • 正则表达式的高手看过来:求提取电子邮件的正则表达式(不是检验)
  • 【!!!小妹又来请教几个简单的正则表达式!!!】
  • 又一个关于正则表达式的问题,救救我~~

关键词

  • writeline
  • slist
  • console
  • regexoptions
  • groups
  • 匹配
  • cellpadding
  • cellspacing
  • match
  • regex

得分解答快速导航

  • 帖主:shixueli
  • saucer

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo