Home  >  Article  >  Web Front-end  >  JavaScript regular expression matching div style tag_javascript skills

JavaScript regular expression matching div style tag_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:10:421679browse

Test string:

<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>

First try: faae8c93a4b8e255565fac1097af97cc/]*>(.*?)531ac245ce3e4fe3d50054a55f265927 It is found that there is no match if there is a newline, because . matches except the newline character (/n) any character.

Second attempt:

To match dc6dce4a544fdca2df29d5ac0ea9906b just replace c9ccee2e6ea535a969eb3f532ad9fe89 with dc6dce4a544fdca2df29d5ac0ea9906b

1. Replace only the first matching c9ccee2e6ea535a969eb3f532ad9fe89

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

2. Will replace all c9ccee2e6ea535a969eb3f532ad9fe89 tags in all testData

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

g: represents global matching.

i: stands for case-insensitive matching.

m: Indicates that multiple lines can be matched.

The above content is the JavaScript regular expression matching dc6dce4a544fdca2df29d5ac0ea9906bc9ccee2e6ea535a969eb3f532ad9fe89 tag introduced by the editor. I hope it will be helpful to everyone!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn