js正則匹配table tr
我覺得比ijao簡單,但是腦子就是轉(zhuǎn)不過彎。。。。請正則高手看看阿。
<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,
分享一個函數(shù)
//普通替換 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|\ \;| | |\xc2\xa0)*?<\/p>/ig, ""); str=str.replace(/<p>\s*?<\/p>/ig,""); str=str.replace(/<p> <\/p>/ig,""); str=str.replace(/<br type="_moz">\n <\/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 <\/p>/ig, "</p>"); str=str.replace(/<br>\n <\/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的詳細內(nèi)容,更多關(guān)于js正則table的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
常用正則表達式知識點解讀及判讀有效數(shù)字、手機號郵箱正則表達式
正則表達式式應(yīng)用非常廣泛,本文給大家收集整理些正則表達式知識點解讀及判斷有效數(shù)字、手機號郵箱正則表達式,對常用正則表達式相關(guān)知識感興趣的朋友一起學(xué)習吧2015-11-11一文搞懂正則表達式基礎(chǔ)語法以及如何應(yīng)用
正則表達式是一種描述字符串結(jié)構(gòu)的語法規(guī)則,是用于匹配字符串中字符組合的模式,同時正則表達式也是對象,下面這篇文章主要給大家介紹了關(guān)于如何通過一文搞懂正則表達式基礎(chǔ)語法以及如何應(yīng)用的相關(guān)資料,需要的朋友可以參考下2022-09-09詳解PHP正則表達式替換實現(xiàn)(PHP preg_replace,PHP preg_replace)
PHP正則表達式替換實現(xiàn)是如何的呢?首先向你介紹下PHP preg_replace,PHP preg_replace的使用是我們實現(xiàn)的方法,那么對于PHP正則表達式替換實現(xiàn)過程我們從實例入手,感興趣的跟著小編一起了解了解吧2015-09-09js正則表達式之RegExp對象屬性lastIndex,lastMatch,lastParen,lastContext,
js正則表達式之RegExp對象屬性lastIndex,lastMatch($&),lastParen($+),lastContext,rightContext屬性的講解2012-10-10