简体   繁体   中英

Regex to match all closing HTML tags

For some reason, I need to remove all closing HTML tags from a string in PHP, so I need a Regular Expression to match all closing HTML Tags. I'm extremely unexperienced with Regular Expressions, so I tried using /\\<\\\\.*\\>/g and /<\\\\.*>/g , but that didn't work. What should I use instead?

Please note that I only want to match closing HTML tags. Opening HTML Tags should remain untouched. Thanks in advance!

Matching HTML with a regex is not a good idea, but if you have to, you can use

/<\/[^<>]*>/g

Explanation:

</     # Match </
[^<>]* # Match any number of characters except angle brackets
>      # Match >

Use this regex:

</.+?>

or

/<\/.+?>/

That will do.

Live Demo

/<\/[\w^_]*>/

因为您不希望匹配标记中的?。=-和_。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM