JS replaces the contents of the script tag, including line break

Source: Internet
Author: User

These days in the project you need to use JS to replace the contents of the script tag

You can make a match with your own string, but once you have a large string of DOM content to match,

has been prompted to fail.

Surf the internet to find a lot of information, has not matched, debugging for a long time

Depressed time, a flash of light, difficult is the problem of the line, a test, sure enough.

var str = ' lkjkjk ' + ' <script type=text/html>  abc </SCRIPT> 'var reg =/<script.* >.*<\/script>/Gialert (reg.test (str))

Prompt true

var str = ' lkjkjk ' + ' <script type=text/html>  abc\n </SCRIPT> 'var reg =/<script.* >.*<\/script>/Gialert (reg.test (str))

Prompt false

Finally, the line break is added to the matching rule to successfully

var str = ' <script type=text/html>  ffff  \n</script> 'var reg =/<script.*> ([\s\s]*?) <\/script>/Gialert (reg.test (str))

JS replaces the contents of the script tag, including line break

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.