js正则匹配table tr

所属分类: 网络编程 / 正则表达式 阅读数: 353
收藏 0 赞 0 分享

我觉得比ijao简单,但是脑子就是转不过弯。。。。请正则高手看看阿。

<textarea id="txt"> 
<table border=1 width="20%">           
        <tr><th>title</th><th>title2</th></tr> 
           <tr rs="{id:\'section006\'}"><td>data1</td><td>data2      </td> 
           </tr> 
           <tr ><td>data1</td><td>data2</td></tr> 
</table> 
</textarea> 

<script> 
var str = document.getElementById('txt').value; 
alert(str); 
</script>

/<tr[^>]*>[\s\S]*?<\/tr>/gi,

分享一个函数

//普通替换
function doRepNormal(s){
var str=s.replace(/<p><br type="_moz">\s*?<\/p>/ig,"");
str=str.replace(/<p>\s*?<br type="_moz">\s*?<\/p>/ig, "");
str=str.replace(/<p>(\s|\&nbsp\;| | |\xc2\xa0)*?<\/p>/ig, "");
str=str.replace(/<p>\s*?<\/p>/ig,"");
str=str.replace(/<p>&nbsp;<\/p>/ig,"");
str=str.replace(/<br type="_moz">\n&nbsp;<\/p>/ig, "</p>");
str=str.replace(/<br type="_moz">\s*?<\/p>/ig, "</p>");
str=str.replace(/<br\s*?\/?>\s*?<\/p>/ig, "</p>");
str=str.replace(/<br \/>\n&nbsp;<\/p>/ig, "</p>");
str=str.replace(/<br>\n&nbsp;<\/p>/ig, "</p>");
//表格替换 
str=str.replace(/<table[^<>]*>/ig, "<table>");
str=str.replace(/<thead[^<>]*>/ig, "<thead>");
str=str.replace(/<tbody[^<>]*>/ig, "<tbody>");
str=str.replace(/<tfoot[^<>]*>/ig, "<tfoot>");
str=str.replace(/<tr[^<>]*>/ig, "<tr>");
str=str.replace(/<th [^<>]*>/ig, "<th>");
str=str.replace(/<td[^<>]*>/ig, "<td>");
str=str.replace(/<th>\s*?<p>/ig, "<th>");
str=str.replace(/<\/p>\s*?<\/th>/ig, "</th>");
str=str.replace(/<td[^<>]*>\s*?<p>/ig, "<td>");
str=str.replace(/<td>\s*?<p>/ig, "<td>");
str=str.replace(/<\/p>\s*?<\/td>/ig, "</td>");
return str;
}

以上就是js正则匹配table tr的详细内容,更多关于js正则table的资料请关注脚本之家其它相关文章!

更多精彩内容其他人还在看

正则表达式——匹配规则介绍

这篇文章主要介绍了正则表达式——匹配规则介绍,需要的朋友可以参考下
收藏 0 赞 0 分享

JavaScript 中的正则表达式(推荐)

正则表达式通常用于在文本中查找匹配的字符串,js正则表达式在程序开发中应用非常广泛,本文给大家介绍JavaScript 中的正则表达式(推荐),感兴趣的朋友一起学习吧
收藏 0 赞 0 分享

Java正则表达式入门基础篇(新手必看)

这篇文章给大家介绍java正则表达式入门基础篇, 由于正则表达式是一个很庞杂的体系,所以我仅例举些入门的概念,更多的请参阅相关书籍及自行摸索。感兴趣的朋友一起跟着小编来看看吧
收藏 0 赞 0 分享

linux正则表达式awk详解

这篇文章主要介绍了linux正则表达式awk的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

notepad++ 等用正则表达式自动添加sql引号的技巧

本篇文章给大家介绍notepad用正则表达式自动添加sql引号的技巧,,需要的朋友可以参考下
收藏 0 赞 0 分享

常见的正则表达式问题

这篇文章主要介绍了常见的正则表达式问题,需要的朋友可以参考下
收藏 0 赞 0 分享

Linux正则表达式特性详解及BRE与ERE的异同点

本篇文章给大家介绍linux正则表达式特性及BRE与ERE的不同,Linux正则表达式(Regular Expression)主要遵从POSIX BRE或者POSIX ERE标准,对linux正则表达式感兴趣的朋友可以参考下本篇文章
收藏 0 赞 0 分享

Linux下如何使用grep命令查找带有tab(退格)的字符

本文给大家介绍linux下如何使用grep命令查找带有tab(退格)的字符,涉及到linux grep 查找带有tab的字符方面的知识,对linux grep tab感兴趣的朋友可以参考下本篇文章
收藏 0 赞 0 分享

WEB开发时常用的正则表达式(PHP和Javascript)

这篇文章主要介绍了WEB开发中最常用最实用的正则表达式及其用法,需要的朋友可以参考下
收藏 0 赞 0 分享

比较全面的C 、Java、JavaScript中的正则表达式详解

正则表达式(Regular Expression) 就是用某种模式去匹配一类字符串的公式。本篇文章给大家介绍C 、Java、JavaScript中的正则表达式,本文介绍的非常全面,感兴趣的朋友一起看看吧
收藏 0 赞 0 分享
查看更多