校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > 正則表達式替換table表格中的樣式與空標記(保留rowspan與colspan)

正則表達式替換table表格中的樣式與空標記(保留rowspan與colspan)

熱門標簽:襄陽房產電銷機器人招商 百度地圖標注飯店位置怎么 百度地圖標注名編輯 怎么在高德地圖標注行走軌跡 個性化地圖標注在線 安徽移動外呼系統 清遠陽山400電話號碼如何申請 深圳400電話辦理那家好 施工地圖標注怎么做

完整測試代碼

script>
var str='p>';
str='table id="tblSort" cellspacing="0" helvetica="" sans="">tr id="sdf">td style="color:red" class="ok" colspan="8" height="500" rowspan="5">';
str+='td style = "color:blue" style="color:blue" colspan="8" style="color:red" rowspan="5">';
str+='td id="asdfj" class="dbclick">span id="s159015" class="p_check">a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GET/a> a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >PING/a> a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Trace/a> a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Dig/a>/span>/td>';
str+='td class="sdf" colspan="8" style="color:red" rowspan="5">p style="color:red">jb51.net/p>/td>';
str+='td class="sdf" colspan="8" style="color:red" rowspan="5" width="100">/td>/tr>/table>';

str+='table>tr style = "color:bluefffffffffffffffffffffffffffffffffffffffffff">td style="color:green" class="ok" colspan="8" height="500" rowspan="5">';
str+='tr id="trinfo146798" class="alt">   td id="tdinfo146798" colspan="16">/td>  /tr>';
str+='td id="asdfj" class="dbclick">span id="s159015" class="p_check">a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >GET/a> a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >PING/a> a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Trace/a> a style="text-decoration: none; color: rgb(0,136,255)"  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Dig/a>/span>/td>';
str+='td class="sdf" colspan="8" style="color:red" rowspan="5">p style="color:red">jb51.net/p>/td>';
str+='td class="sdf" colspan="8" style="color:red" rowspan="5" width="100"> font color="#0f0000">122.227.189.106 [中國浙江寧波電信]/font>br />/td>/tr>/table>';

str+='p>img alt="" src="http://img.jbzj.com/file_images/article/202004/2020041112113912.png" />/p>';
str+='p>選擇安裝然后選擇全新的sql server獨立安裝/p>';
str+='p>img alt="" src="http://img.jbzj.com/file_images/article/202004/2020041112113913.png" />/p>';

console.log(str);

//去除table的寬度
str=str.replace(/table[^>]*>/ig, "table>");
str=str.replace(/table[^>]*>[\s\S]*?\/table>/gi,function(match,capture){
match=match.replace(/(style|class|id)[\s]*=[\s]*("|')[^>"']*?\2/gi,'');
match=match.replace(/\/?span[^>]*>/gi,'');
match=match.replace(/p [^>]*>|\/p>/gi,'');
match=match.replace(/font[^>]*>|\/font>/gi,'');
return match;
});

//alert(str);
console.log(str);
/script>

原來的代碼是這樣的

//普通替換
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">\nnbsp;\/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 \/>\nnbsp;\/p>/ig, "/p>");
str=str.replace(/br>\nnbsp;\/p>/ig, "/p>");
//表格替換 
str=str.replace(/table[^>]*>/ig, "table>");
str=str.replace(/table[^>]*>[\s\S]*?\/table>/gi,function(match,capture){
match=match.replace(/style[\s]*=[\s]*("|')[^>"']*?\1/gi,'');
match=match.replace(/cl\ass[\s]*=[\s]*("|')[^>"']*?\1/gi,'');
match=match.replace(/id[\s]*=[\s]*("|')[^>"']*?\1/gi,'');
match=match.replace(/font[^>]*>|\/font>/gi,'');
return match;
});
str=str.replace(/td[^>]*>/gi,function(match,capture){
match=match.replace(/style[\s]*=[\s]*("|')[^>"']*?\1/gi,'');
match=match.replace(/cl\ass[\s]*=[\s]*("|')[^>"']*?\1/gi,'');
match=match.replace(/id[\s]*=[\s]*("|')[^>"']*?\1/gi,'');
return match;
});
return str;
}

后臺修改成這樣的

str=str.replace(/table[^>]*>/ig, "table>");
str=str.replace(/table[^>]*>[\s\S]*?\/table>/gi,function(match,capture){
match=match.replace(/(style|class|id)[\s]*=[\s]*("|')[^>"']*?\2/gi,'');
match=match.replace(/\/?span[^>]*>/gi,'');
match=match.replace(/p [^>]*>|\/p>/gi,'');
match=match.replace(/font[^>]*>|\/font>/gi,'');
return match;
});

經過測試發現chrome中正常,但在ie8與ie7中有bug無法實現class與id的替換,文檔聲明!DOCTYPE html>都會影響一些結果,真是漲了見識

正好看到別的人分享的先留存一份,后續更新

用正則表達式取出table中的所有行(支持嵌套table)

此是通過csdn詢問得高人之手寫的。
謝謝gzdiablo

表達式:

tr[^>]*>(?:(?:\s|\S)*?(?=table|/tr>)(?(table)table[^>]*>(?:\s|\S)*?(?:/table>|(?:(?:table[^>]*>(?:\s|\S)*?/table>(?:\s|\S)*?)*?/table>))(?:\s|\S)*?|))*/tr>

一條表達式就可以獲取你想要的
寫得好辛苦
測試:

table width="300" border="1" cellspacing="0" cellpadding="0">
 tr>
 td>nbsp;/td>
 td>table width="100%" border="1" cellspacing="0" cellpadding="0">
  tr>
  td>nbsp;/td>
  /tr>

 /table>
  table width="100%" border="1" cellspacing="0" cellpadding="0">
  tr>
   td>nbsp;/td>
  /tr>
  /table>/td>
 td>nbsp;/td>
 /tr>
 tr>
 td>nbsp;/td>
 td>nbsp;/td>
 td>table width="100%" border="1" cellspacing="0" cellpadding="0">

  tr>
  td>nbsp;/td>
  /tr>
 /table>/td>
 /tr>
 tr>
 td>table width="100%" border="1" cellspacing="0" cellpadding="0">
  tr>
  td>nbsp;/td>
  /tr>

 /table>/td>
 td>nbsp;/td>
 td>nbsp;/td>
 /tr>
/table>

-------------------獲取3個match

============================================match1
  tr>
    td>nbsp;/td>
    td>table width="100%" border="1" cellspacing="0" cellpadding="0">
      tr>
        td>nbsp;/td>
        /tr>

    /table>
      table width="100%" border="1" cellspacing="0" cellpadding="0">
        tr>
          td>nbsp;/td>
        /tr>
      /table>/td>
    td>nbsp;/td>
  /tr>
==============================================match2
  tr>
    td>nbsp;/td>
    td>nbsp;/td>
    td>table width="100%" border="1" cellspacing="0" cellpadding="0">

      tr>
        td>nbsp;/td>
        /tr>
    /table>/td>
  /tr>
==============================================match3
  tr>
    td>table width="100%" border="1" cellspacing="0" cellpadding="0">
      tr>
        td>nbsp;/td>
        /tr>

    /table>/td>
    td>nbsp;/td>
    td>nbsp;/td>
  /tr>

正則表達式匹配html標簽table

首先,要匹配任意內容“.”是不行的,因為不匹配“\n”,取不到想要的內容,所以有了如下表達式:
    [\s\S]*

當然,你也可以用 “[\d\D]*”、“[\w\W]*” 來表示。

現在我們來匹配一個html標簽,匹配table如下:

table.*?>[\s\S]*\/table>

table.*?>[\s\S]*?\/table>

以上兩個表達式,一個加了"?"和一個卻不加“?”,那么這有什么區別呢?
我們知道“?”在正則表達式里是一個通配符:匹配前面的子表達式零次或一次,或指明一個非貪婪限定符。

在這里,通過測試,我們得出這樣的結論:在不加“?”的情況下,在匹配下面一段內容的時候:

table>這是第一個table/table>
我不是table里的內容
table>這是第二個table/table>
我也不是table里的內容
table>這是第三個table/table>

會把以table>開始,/table>結束的內容都匹配出來

加了“?”之后,只匹配第n個匹配的內容

完整測試代碼腳本之家小編提供

script>
var str='table>這是第一個table/table>';
str+='我不是table里的內容';
str+='table>這是第二個table/table>';
str+='我也不是table里的內容';
str+='table>這是第三個table/table>';

var reg1 = /table.*?>[\s\S]*\/table>/gi;
var res1 = str.match(reg1);
console.log(res1) 
var reg2 = /table.*?>[\s\S]*?\/table>/gi;
var res2 = str.match(reg2);
console.log(res2) 
/script>

效果圖

以上就是正則表達式替換table表格中的樣式與空標記(保留rowspan與colspan)的詳細內容,更多關于正則表達式替換table表格的資料請關注腳本之家其它相關文章!

標簽:南昌 欽州 延邊 臨夏 中衛 黑河 阜陽 駐馬店

巨人網絡通訊聲明:本文標題《正則表達式替換table表格中的樣式與空標記(保留rowspan與colspan)》,本文關鍵詞  正則,表達式,替換,table,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《正則表達式替換table表格中的樣式與空標記(保留rowspan與colspan)》相關的同類信息!
  • 本頁收集關于正則表達式替換table表格中的樣式與空標記(保留rowspan與colspan)的相關信息資訊供網民參考!
  • 推薦文章
    校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃
    av在线播放成人| 蜜桃av一区二区在线观看| 夜夜爽夜夜爽精品视频| 亚洲影院理伦片| 韩国欧美国产1区| 99久久久无码国产精品| 欧美精品久久99| 欧美激情中文字幕| 亚洲一区二区成人在线观看| 久久国产尿小便嘘嘘尿| 91亚洲永久精品| 日韩一区二区三区四区五区六区 | 国产一区二区不卡在线| 99久久国产免费看| 日韩欧美专区在线| 亚洲欧洲av在线| 久久99精品久久久久久国产越南| 懂色av一区二区三区免费看| 欧美日韩精品欧美日韩精品一综合| 久久嫩草精品久久久精品一| 亚洲午夜影视影院在线观看| 国产福利一区在线观看| 欧美日韩国产高清一区二区三区 | 国产成人鲁色资源国产91色综| 日本精品视频一区二区| www国产精品av| 亚洲国产综合色| 成人性生交大片免费| 日韩一卡二卡三卡国产欧美| 亚洲嫩草精品久久| 国产成人精品午夜视频免费| 欧美一区二区久久| 亚洲精品中文字幕乱码三区| 国产精品亚洲第一| 91麻豆精品国产91久久久久| 亚洲色图另类专区| 国产精品 日产精品 欧美精品| 91精品免费观看| 亚洲第一精品在线| 91丨porny丨首页| 国产欧美精品一区二区三区四区 | 日韩精品中文字幕在线一区| 亚洲国产视频一区| 色综合亚洲欧洲| 国产精品久久看| 欧美日韩一区二区在线视频| 国产欧美精品一区二区三区四区 | 国产目拍亚洲精品99久久精品| 日日夜夜一区二区| 在线一区二区三区四区五区| 国产精品久久久久影院老司| 国产精品91一区二区| 精品日韩一区二区| 麻豆91免费看| 日韩欧美国产系列| 久久激情综合网| 欧美成人性福生活免费看| 免费av网站大全久久| 制服丝袜亚洲网站| 性做久久久久久| 欧美日韩和欧美的一区二区| 亚洲一二三区在线观看| 欧美私人免费视频| 亚洲狼人国产精品| 在线免费不卡视频| 亚洲一区在线电影| 欧美亚洲综合网| 午夜精品久久久久久久| 欧美麻豆精品久久久久久| 亚洲国产另类av| 精品视频1区2区| 三级在线观看一区二区| 日韩亚洲欧美中文三级| 美女性感视频久久| 欧美成人综合网站| 国产综合久久久久影院| 国产亚洲欧美日韩日本| 成人不卡免费av| 亚洲欧美一区二区三区极速播放| 99精品久久免费看蜜臀剧情介绍| 日韩美女视频19| 欧美在线三级电影| 日本在线播放一区二区三区| 日韩欧美色综合网站| 国产九色sp调教91| 亚洲欧洲日韩av| 欧美综合一区二区| 天堂精品中文字幕在线| 欧美大片免费久久精品三p| 国产一区二区三区电影在线观看 | 91小视频在线免费看| 亚洲一区在线电影| 欧美一卡二卡三卡四卡| 国产精品一色哟哟哟| 亚洲天天做日日做天天谢日日欢 | 视频一区国产视频| 精品成人a区在线观看| 不卡av在线网| 亚洲成人自拍偷拍| 亚洲精品一线二线三线| 91尤物视频在线观看| 日日夜夜精品免费视频| 国产色91在线| 在线中文字幕一区二区| 久久精品国产久精国产| 中文字幕精品综合| 欧美日韩激情一区二区| 国产九色精品成人porny| 国产激情精品久久久第一区二区 | 欧美午夜精品一区| 久久av中文字幕片| 亚洲欧美综合另类在线卡通| 欧美高清hd18日本| 粉嫩久久99精品久久久久久夜| 一卡二卡三卡日韩欧美| 日韩精品在线一区二区| 99综合影院在线| 日韩不卡手机在线v区| 中文字幕不卡一区| 欧美一区二区在线看| 成人app在线观看| 奇米综合一区二区三区精品视频| 国产亚洲欧美中文| 欧美猛男男办公室激情| 成人免费观看视频| 免费看欧美女人艹b| 国产精品看片你懂得| 欧美一区二区三区啪啪| 97国产精品videossex| 久久成人羞羞网站| 亚洲午夜av在线| 国产精品网站在线观看| 91精品蜜臀在线一区尤物| 91一区二区在线观看| 久久国产欧美日韩精品| 亚洲国产欧美日韩另类综合| 亚洲国产精品成人综合色在线婷婷 | 精品国产乱码久久久久久浪潮 | 亚洲一区二区不卡免费| 亚洲国产成人一区二区三区| 日韩欧美一区二区久久婷婷| 色综合视频一区二区三区高清| 激情丁香综合五月| 日韩影院精彩在线| 亚洲一区二区在线观看视频| 国产精品乱子久久久久| 久久亚洲综合色| 日韩欧美一区二区在线视频| 欧美在线视频日韩| 99热精品国产| 成人黄色一级视频| 国产精品一色哟哟哟| 美女视频黄a大片欧美| 亚洲成年人影院| 亚洲欧美激情一区二区| 国产欧美精品一区二区色综合 | 国产99久久久久| 精品亚洲免费视频| 日韩精品国产欧美| 亚洲成人免费av| 亚洲一二三四区| 艳妇臀荡乳欲伦亚洲一区| 国产精品久久久久aaaa| 亚洲精品一区二区三区精华液| 日韩欧美综合一区| 91精品国产麻豆| 在线播放日韩导航| 欧美日韩精品电影| 久久久精品tv| 国产日韩欧美a| 国产人成亚洲第一网站在线播放| 欧美变态tickle挠乳网站| 欧美精品第1页| 777午夜精品视频在线播放| 欧美精品一二三| 欧美日韩在线不卡| 欧美日韩五月天| 欧美日本乱大交xxxxx| 欧美日韩精品欧美日韩精品一| 欧美视频在线一区| 欧美午夜精品免费| 欧美日韩成人高清| 91精品欧美一区二区三区综合在 | 国产麻豆一精品一av一免费 | 国产精品家庭影院| 成人免费一区二区三区视频| 亚洲欧洲韩国日本视频| 亚洲人精品午夜| 亚洲午夜电影在线观看| 日韩精品电影一区亚洲| 免费成人av在线播放| 狠狠狠色丁香婷婷综合激情| 国产一本一道久久香蕉| www.在线成人| 在线影院国内精品| 欧美久久久久久久久中文字幕| 日韩一区二区精品| 久久久久国产精品厨房| 中文字幕在线观看不卡| 一区二区三区蜜桃|