国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JavaScript正則表達式匹配 div style標簽

2019-11-20 10:23:25
字體:
來源:轉載
供稿:網友

測試字符串:

<style>v/:* { BEHAVIOR: url(#default#VML) } o/:* { BEHAVIOR: url(#default#VML) } w/:*{ BEHAVIOR: url(#default#VML) } .shape { BEHAVIOR: url(#default#VML) }</style> abcdefg <style>@font-face { font-family: Wingdings;} @font-face{ font-family: Wingdings; } @font-face{ font-family: Calibri;} @font-face { font-family: Tahoma; } @page WordSection1 {size: 8.5in 11.0in; margin: 1.0in 1.0in 1.0in 1.0in; } P.MsoNormal { FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif" } LI.MsoNormal { FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif" } DIV.MsoNormal { FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman","serif" } H1 { FONT-WEIGHT: bold; FONT-SIZE: 24pt; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in;FONT-FAMILY: "Times New Roman","serif";mso-style-priority: 9; mso-style-link: "Heading 1 Char"; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto}A:link { COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99} SPAN.MsoHyperlink{ COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99 } A:visited { COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99} SPAN.MsoHyperlinkFollowed { COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99 } P { FONT-SIZE: 12pt; MARGIN-LEFT: 0in; MARGIN-RIGHT: 0in; FONT-FAMILY: "Times New Roman","serif"; mso-style-priority: 99; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto }P.MsoAcetate { FONT-SIZE: 8pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Tahoma","sans-serif"; mso-style-priority: 99; mso-style-link: "Balloon Text Char"} LI.MsoAcetate{ FONT-SIZE: 8pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Tahoma","sans-serif"; mso-style-priority: 99; mso-style-link: "Balloon Text Char"} DIV.MsoAcetate { FONT-SIZE: 8pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Tahoma","sans-serif";mso-style-priority: 99; mso-style-link: "Balloon Text Char" } SPAN.Heading1Char { FONT-WEIGHT: bold; mso-style-priority: 9; mso-style-link: "Heading 1"; mso-style-name: "Heading 1 Char" } SPAN.EmailStyle19 { COLOR: #1f497d; FONT-FAMILY: "Arial","sans-serif"; mso-style-type: personal-reply } SPAN.BalloonTextChar { FONT-FAMILY: "Tahoma","sans-serif"; mso-style-priority: 99; mso-style-link: "Balloon Text"; mso-style-name: "Balloon Text Char" } .MsoChpDefault { FONT-SIZE: 10pt; mso-style-type: export-only } DIV.WordSection1 { page: WordSection1 } OL { MARGIN-BOTTOM: 0in } UL { MARGIN-BOTTOM: 0in }</style>

第一次嘗試:<style[^>/]*>(.*?)</style> 發現有換行的情況匹配不了,因為.是匹配除了換行符(/n)以外的任意一個字符。

第二次嘗試:<style(([/s/S])*?)</style> 成功

匹配<div>只需要把<style>換成<div>即可

1. 只替換匹配到的第一個<style>

var result= testData.replace(<style(([/s/S])*?)<//style>, '');

2. 會替換所有testData中所有的<style>標簽

var result= testData.replace(/<style(([/s/S])*?)<//style>/g, '');

g:代表可以進行全局匹配。

i:代表不區分大小寫匹配。

m:代表可以進行多行匹配。

以上內容是小編給大家介紹的JavaScript正則表達式匹配<div><style>標簽,希望對大家有所幫助!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德安县| 金平| 禹州市| 商水县| 尚志市| 台山市| 五家渠市| 芜湖市| 奈曼旗| 北京市| 得荣县| 东乌珠穆沁旗| 连山| 五莲县| 从化市| 磴口县| 来凤县| 栾川县| 衡阳市| 临武县| 衡山县| 琼中| 荆州市| 灵石县| 乌鲁木齐县| 岗巴县| 龙口市| 托克逊县| 明溪县| 新和县| 通榆县| 祥云县| 信阳市| 乐平市| 普兰县| 潜山县| 马公市| 永春县| 阿拉尔市| 兴业县| 灵寿县|