JavaScript正則表達(dá)式匹配 div style標(biāo)簽
來源:易賢網(wǎng) 閱讀:1244 次 日期:2016-07-20 15:10:07
溫馨提示:易賢網(wǎng)小編為您整理了“JavaScript正則表達(dá)式匹配 div style標(biāo)簽”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了JavaScript正則表達(dá)式匹配<div><style>標(biāo)簽 的相關(guān)資料,需要的朋友可以參考下

測(cè)試字符串:

<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> 發(fā)現(xiàn)有換行的情況匹配不了,因?yàn)?是匹配除了換行符(/n)以外的任意一個(gè)字符。

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

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

1. 只替換匹配到的第一個(gè)<style>

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

2. 會(huì)替換所有testData中所有的<style>標(biāo)簽

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

g:代表可以進(jìn)行全局匹配。

i:代表不區(qū)分大小寫匹配。

m:代表可以進(jìn)行多行匹配。

以上內(nèi)容是小編給大家介紹的JavaScript正則表達(dá)式匹配<div><style>標(biāo)簽,希望對(duì)大家有所幫助!

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:JavaScript正則表達(dá)式匹配 div style標(biāo)簽
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)