正则表达式:从“内容”中排除html标签 [英] Regular Expression: exclude html tags from "content"

查看:163
本文介绍了正则表达式:从“内容”中排除html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一位朋友问我这个问题,因为我对RegExp的了解还不是很好。

One friend asked me this and as my knowledge on RegExp is not so good yet here I am.

如何从这个字符串中排除HTML标签?

How can exclude the HTML tags from this string?

re<br>na<br>to<br>galvao

我已经尝试了一些RegExp,但它没有按照我的预期工作。

I've tried some RegExp but it didn't work as I was expecting.

(.*)<.*>(.*)

但是这个RegExp获得第一个<最后一个>。

But this RegExp gets the first < and the last >.

任何想法?

推荐答案

这是一个快速的方法:

var content = "re<br>na<br>to<br>galvao";
content = content.replace(/<[^>]*>/g,'');

这篇关于正则表达式:从“内容”中排除html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆