[英]Regular Expression: exclude html tags from “content”
One friend asked me this and as my knowledge on RegExp is not so good yet here I am. 一位朋友问我这个问题,因为我对RegExp的了解并不是很好。
How can exclude the HTML tags from this string? 如何从此字符串中排除HTML标记?
re<br>na<br>to<br>galvao
I've tried some RegExp but it didn't work as I was expecting. 我已经尝试了一些RegExp,但它没有像我期望的那样工作。
(.*)<.*>(.*)
But this RegExp gets the first < and the last >. 但是这个RegExp获得了第一个<和最后一个>。
Any ideas? 有任何想法吗?
this is a quick way to do it: 这是一种快速的方法:
var content = "re<br>na<br>to<br>galvao";
content = content.replace(/<[^>]*>/g,'');
Match all html tags with this regex: 将所有html标记与此正则表达式匹配:
<("[^"]*?"|'[^']*?'|[^'">])*>
see demo here: http://regex101.com/r/fA0oT4 请参阅此处的演示: http : //regex101.com/r/fA0oT4
You could use a non-greedy match. 你可以使用非贪婪的比赛。 According to the answer to this question , in javascript it is *?
根据这个问题的答案,在javascript中它是*?
So, assuming this is the only problem with your regex, it should work with 所以,假设这是你的正则表达式的唯一问题,它应该适用
(.*?)<.*?>(.*?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.