In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "regular expression how to replace the style in the table table and the empty tag while retaining rowspan and colspan", the content of the article is simple and clear, easy to learn and understand, please follow the editor's ideas slowly in-depth, together to study and learn "regular expression how to replace the style and empty tag in the table table while retaining rowspan and colspan" bar.
Complete test code
Var str='
'; str='';str+='';str+='GET PING Trace Dig';str+='jb51.net
'; str+='';str+='';str+=''; str+='GET PING Trace Dig';str+='jb51.net
'; str+=' 122.227.189.106 [Ningbo Telecom, Zhejiang, China]'; str+='
'; str+='
Select installation and then choose a new sql server stand-alone installation
'; str+='
'; console.log (str); / / remove the width of table str=str.replace (/] * > / ig, ""); str=str.replace (/] * > [\ s\ S] *? / gi,function (match,capture) {match=match.replace (/ (style | class | id) [\ s] * = [\ s] * ("|') [^'] *?\ 2Pandle giggle'); match=match.replace (/ / gi,''); match=match.replace (/ | / gi,'') Match=match.replace (/ | / gi,''); return match;}); / / alert (str); console.log (str)
The original code looks like this.
/ / normal replacement function doRepNormal (s) {var str=s.replace (/
\ s*?/ig, ""); str=str.replace (/
\ s*?/ig, ""); str=str.replace (/
(\ s |\ & nbsp\; |\ xc2\ xa0) *? / ig, "); str=str.replace (/
\ s*?/ig, ""); str=str.replace (/
/ ig, ""); str=str.replace (/\ n / ig, "
"); str=str.replace (/\ s*?/ig,"
"); str=str.replace (/\ s*?/ig,"
"); str=str.replace (/\ n / ig,"
"); str=str.replace (/
\ n / ig, "
"); / / form replacement str=str.replace (/] * > / ig,"); str=str.replace (/] * > [\ s\ S] *? / gi,function (match,capture) {match=match.replace (/ style [\ s] * = [\ s] * (" | |') [^ "] *?\ 1Gimeng'); match=match.replace (/ cl\ ass [\ s] * = [\ s] * (" | ") [') [^"] *?\ 1Compare giggles') Match=match.replace (/ id [\ s] * = [\ s] * ("| |') [^"] *?\ 1Gizhime'); match=match.replace (/ | / gi,''); return match;}); str=str.replace (/] * > / gi,function (match,capture) {match=match.replace (/ style [\ s] * = [\ s] * ("| |') [^'"] *?\ 1Gimagram') Match=match.replace (/ cl\ ass [\ s] * = [\ s] * ("| |') [^") [^'] *?\ 1Gime return str;'); match=match.replace (/ id [\ s] * = [\ s] * ("| |') [^"] *?\ 1LGI *); return str;})
The background is modified like this.
Str=str.replace (/] * > / ig, ""); str=str.replace (/] * > [\ s\ S] *? / gi,function (match,capture) {match=match.replace (/ (style | class | id) [\ s] * = [\ s] * ("| |') [^"] *?\ 2Gimeng'); match=match.replace (/ / gi,''); match=match.replace (/ | / gi,''); match=match.replace (/ | / gi,''); return match;})
After testing, it is found that chrome is normal, but there are bug in ie8 and ie7 that can not replace class and id. The document declaration will affect some results.
Just in time to see what others share, keep a copy first, and update it later.
Fetch all lines in table with regular expressions (support for nested table)
This is handwritten by the person who asked about it through csdn.
Thank you, gzdiablo.
Expression:
] * > (?: (?:\ s |\ S) *? (? = (?:\ s |\ S) *? (?:\ s |\ S) *?)) (?:\ s |\ S) * |) *
An expression can get what you want.
It's hard to write.
Test:
-get 3 match
= match2
= match3
= match4
The regular expression matches the html tag table
First of all, match anything. " It doesn't work, because it doesn't match "\ n" and you can't get what you want, so you have the following expression:
[\ s\ S] *
Of course, you can also use "[\ d\ D] *" and "[\ w\ W] *".
Now let's match a html tag, matching table as follows:
[\ s\ S] *
Or
[\ s\ S] *?
Of the above two expressions, one added "?" And one without adding "?", so what's the difference?
We know "?" A wildcard in a regular expression: matches the previous subexpression zero or once, or indicates a non-greedy qualifier.
Here, through the test, we come to the conclusion that we are not adding "?" When matching the following paragraph:
This is the first table.
I'm not part of table.
This is the second table.
I'm not part of table either.
This is the third table.
Will match all the contents that begin and end.
Add "?" After that, only the nth match is matched.
The editor of the complete test code provides
Var str=' this is the first table';str+=' I am not content in table'; str+=' this is the second table';str+=' and I am not content in table'; str+=' this is the third table';var reg1 = / [\ s\ S] * / gi;var res1 = str.match (reg1); console.log (res1) var reg2 = / [\ s\ S] *? / gi;var res2 = str.match (reg2); console.log (res2)
Effect picture
Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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: 263
*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.