请教用正则表达式提取4个字符串

dzh523 2014-03-04 10:49:13
<TD width=58 row="1">1.905</TD>
<TD row="1" ref="-2.020">成本/售价</TD>
<TD width=58 row="1" class=””>3.925</TD>

从上面的字符串中提取1.905,-2.020,成本/售价,3.925这四个。
...全文
310 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
 string sInput = File.ReadAllText(@"C:\Users\myx\Desktop\Test.txt", Encoding.GetEncoding("GB2312"));
            string pattern = @"(?i)<td[^>]*?>(\d+(?:\.\d+)?)</td>\s*?<td[^>]*?ref=(['""]?)([^'""]*?)\2[^>]*?>([^<>]*?)</td>\s*?<td[^>]*?>([^<>]*?)</td>";
            Match m = Regex.Match(sInput, pattern);

            string v1 = m.Groups[1].Value;//"1.905"
            string v2 = m.Groups[3].Value;//"2.020"
            string v3 = m.Groups[4].Value;//"成本/售价"
            string v4 = m.Groups[5].Value;//"3.925"
threenewbee 2014-03-04
  • 打赏
  • 举报
回复
(?<=ref\=\").*?(?=\"\>) (?<=\>).*?(?=\<\/TD\>)
xloveme 2014-03-04
  • 打赏
  • 举报
回复
>(.+)</TD>

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧