The JavaScript Regular Expression matches the div style tag, and the regular expression matches the div

Source: Internet
Author: User

The JavaScript Regular Expression matches the div style tag, and the regular expression matches the div

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 Attempt: <style [^>/] *> (.*?) </Style> a newline character cannot be matched because it matches any character except the linefeed (/n.

Second Attempt: <style ([\ s \ S]) *?) </Style> Successful

To match <div>, replace <style> with <div>.

1. Only Replace the first matching <style>

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

2. All <style> labels in testData will be replaced.

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

G: indicates that global matching can be performed.

I: It indicates case-insensitive matching.

M: indicates that multiple rows can be matched.

The above content is the JavaScript Regular Expression matching <div> <style> label introduced by xiaobian. I hope it will help you!

Articles you may be interested in:
  • Location matching of JS Regular Expressions
  • JS Regular Expression (learning note 2) matching url parameters
  • Use regular expressions in Java/Js to match Nested Html tags
  • Precautions for global matching of regular expressions using exec in Javascript
  • Regular Expression for price matching in javascript
  • Js Regular Expression $1 $2 $3 $4 $5 $6 $7 $8 $9 attribute, return the sub-matching result
  • Example of Case sensitivity for JS application Regular Expression Conversion
  • Usage of question marks in js Regular Expressions
  • Analysis of single-row mode and multi-row mode instances in js Regular Expressions
  • Example of js Regular Expressions test () and exec ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.