JavaScript Regular expression: matches all HTML tags

Source: Internet
Author: User

This regular expression collects in the network, but that website even copies all need to register the member, despises it, therefore does not mention him. Also, the original author could not be the site.

The HTML tag has

In fact, the regular expression matching HTML tags is very short, as follows:

<[^>]+>

That's it, it's gone? Yes. Are you surprised?

Although I can't write my writing, I can read this regular expression. First of all, the HTML tag must start with the < symbol, end with a > sign (whether it's self-closing), just a little tangled in the middle, there may be characters, numbers, quotes, line breaks--but there's no way, because the HTML tag ends because it's there, so the middle of the regular expression is [ ^>]+, which means " any more than 1 characters except the > symbol ."

Test in notepad++, using the above regular expression, to successfully replace all HTML tags. Hey, it's very useful.

This article from: http://jo2.org/javascript%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%9A%E5%8C%B9%E9%85%8D%E6%89% 80%e6%9c%89html%e6%a0%87%e7%ad%be/

JavaScript Regular expression: matches all HTML tags

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.