足球游戏_中国足彩网¥体育资讯$

JavaScript正则表达式匹配 div style标签
来源:易贤网 阅读:1180 次 日期:2016-07-20 15:10:07
温馨提示:易贤网小编为您整理了“JavaScript正则表达式匹配 div style标签”,方便广大网友查阅!

这篇文章主要介绍了JavaScript正则表达式匹配<div><style>标签 的相关资料,需要的朋友可以参考下

测试字符串:

<style>v\:* {

BEHAVIOR: url()

} o\:*

{

BEHAVIOR: url()

} w\:*

{

BEHAVIOR: url()

}

.shape

{

BEHAVIOR: url()

}

</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>标签,希望对大家有所帮助!

中国足彩网信息请查看网络编程
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标