In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how to use js regular matching table,img and remove various tag problems, the article is very detailed, has a certain reference value, interested friends must read it!
Core code
/ / get the contents of the bulletin board s = "$row.detail$"; mainContent = s; / / if more than one table uses the rules annotated below, it will only match as a table / / var tabReg = /] * > ((?! table).) * / gi / / match a single table var tabReg = /] * >\ s * (] * >)? (\ s *] * > [\ s\ S] *?\ s *) * ()?\ s tabReg.test GI; var tabMatch = tabReg.test (s); var tabMatchContentArray = s.match (tabReg); if (tabMatch) {mainContent = s.replace (tabReg, "#") } / / A pair of img tags are matched var imgReg = / |\ / >) / gi; imgMatchContentArray = s.match (imgReg); if (imgReg.test (s)) {/ / replace the img tag with * mainContent = mainContent.replace (imgReg, "*");} / / process the html tag mainContent = mainContent.replace (/ / gi, ""); var pReg1 = /
/ gi; var pReg2 = / / gi; mainContent = mainContent.replace (pReg1, ") .replace (pReg2,"); / / below htmlReg1, htmlReg2 can match any tag / / var htmlReg1 = /] + > / gi;// var htmlReg2 = / / gi;// mainContent = mainContent.replace (htmlReg1, ") .replace (htmlReg2,"); / / mainContent = mainContent.replace (/ & / gi, ")
". Replace (/ @ / gi,)
"); var pageIndex = 1; var size = 500; var tableContentArray = mainContent.split (" # "); var array = []; / / each array in the array divided by table can be divided into several pages var arrayIndex = []; / / store the index var len = 0 of table in the content; for (var item0 I = 0) {/ / get the last subscript var reCount = beginToCurrentPageContent.split ("*") .length-1 of the content starting from the current page location; var contentArray = currentPageContent.split ("*"); currentPageContent = replaceImgContent (contentArray,reCount,imgMatchContentArray) }} else {/ / whether the current page has a location to * get the last * var indexOf = currentPageContent.indexOf ("*"); if (indexOf > = 0) {/ / get the content from the start position to the current page location var beginToCurrentPageContent = mainContent.substr (0meme pageIndex size) / / get the last subscript of * in the content starting to the current page location var reCount = beginToCurrentPageContent.split ("*") .length-1; var contentArray = currentPageContent.split ("*"); currentPageContent = replaceImgContent (contentArray,reCount,imgMatchContentArray) }} if (currentPageContent== "") {alert ("number of pages out of range");} else {document.getElementById ("annouContent") [xss_clean] = currentPageContent } / * currentArray: the current page is divided into * the array replaceCount: the number of content from the start to the current page * matchArray: the matching content of the img tag * / function replaceImgContent (currentArray,replaceCount,matchArray) {var result = ""; for (var i=currentArray.length-1) j = replaceCount-1; I > = 1 Var temp -) {var temp = (matchArray [j] + currentArray [I]); result = temp + result; Jmuri;} result = currentArray [0] + result; return result;}
Here are some additions
Js regular match Delete table
Var reg = / | 123thumb g
An JAVASCRIPT regular expression, leaving only ColSpan and RowSpan in Table
Html = html.replace (/] *? (ColSpan\ s =\ s * ["']? [^" >\ s] * ["]?)? (RowSpan\ s =\ s * ["]? [^ ">\ s] * ["]? [^ >] *?)? > / gi, "")
The above is all the content of the article "how to use js regular matching table,img and remove all kinds of tag problems". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.