js如何使用正则表达式实现过滤HTML标签?(/<[^<>]+>/g)
js如何使用正则表达式实现过滤HTML标签?(/<[^<>]+>/g)
一、总结
js进阶正则表达式实现过滤HTML标签(<>标签中不能包含标签实现过滤HTML标签:/<[^<>]+>/g)
var reg=/<[^<>]+>/g
1、全局匹配g肯定忘记写
2、<>标签中不能包含标签实现过滤HTML标签
二、js进阶正则表达式实现过滤HTML标签
练习5:过滤HTML标签
- 实例描述:将一段带有HTML标签的文本的HTML标签过滤掉,转化为纯文本输出
三、代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>过滤HTML标签</title>
<style type="text/css">
textarea{
width: 60%;
font-size: 18px;
background: rgba(100,200,50,0.3);
}
#text2{
background:rgba(200,100,50,0.3);
}
</style>
</head>
<body>
<textarea id="text1" rows="10" cols="50"></textarea><br><br>
<input type="button" id="btn1" value="过滤HTML标签"><br><br>
<textarea id="text2" rows="10" cols="50"></textarea>
<script type="text/javascript">
var btn1=document.getElementById('btn1')
var text1=document.getElementById('text1')
var text2=document.getElementById('text2')
btn1.onclick=function (){
//var reg=/<.+>/g
var reg=/<[^<>]+>/g //1、全局匹配g肯定忘记写 2、<>标签中不能包含标签实现过滤HTML标签
text2.value=text1.value.replace(reg,'')
}
</script>
</body>
</html>
四、测试题-简答题
1、js正则表达式如何实现过滤HTML标签?
js如何使用正则表达式实现过滤HTML标签?(/<[^<>]+>/g)的更多相关文章
- Java/Js下使用正则表达式匹配嵌套Html标签
转自:http://www.jb51.net/article/24422.htm 以前写过一篇文章讲解如何使用正则表达式完美解决Html嵌套标签的匹配问题(使用正则表达式匹配嵌套Html标签),但是里 ...
- Python通过正则表达式去除(过滤)HTML标签,提取文字
# -*- coding: utf-8-*- import re ##过滤HTML中的标签 #将HTML中标签等信息去掉 #@param htmlstr HTML字符串. def filter_tag ...
- 服务器文档下载zip格式 SQL Server SQL分页查询 C#过滤html标签 EF 延时加载与死锁 在JS方法中返回多个值的三种方法(转载) IEnumerable,ICollection,IList接口问题 不吹不擂,你想要的Python面试都在这里了【315+道题】 基于mvc三层架构和ajax技术实现最简单的文件上传 事件管理
服务器文档下载zip格式 刚好这次项目中遇到了这个东西,就来弄一下,挺简单的,但是前台调用的时候弄错了,浪费了大半天的时间,本人也是菜鸟一枚.开始吧.(MVC的) @using Rattan.Co ...
- php有效的过滤html标签,js代码,css样式标签
过滤html标签�php中太简单了,我们可以直接使用strip_tags函数来实现了,下面给各位整理了一些关于 strip_tags函数的例子. php过滤html的函数:strip_tags(str ...
- java正则表达式过滤html标签
import java.util.regex.Matcher; import java.util.regex.Pattern; /** * <p> * Title: HTML相关的正则表达 ...
- 运用正则表达式在Asp中过滤Html标签代码的四种不同方法
Function RemoveHTML(strHTML)Dim objregExp, Match, MatchesSet objRegExp = New RegexpobjRegExp.IgnoreC ...
- php过滤HTML标签、属性等正则表达式汇总
$str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...
- js进阶正则表达式实现过滤字符串(RegExp对象操作正则表达式)(正则:regular)(表达式:expression)
js进阶正则表达式实现过滤字符串(RegExp对象操作正则表达式)(正则:regular)(表达式:expression) 一.总结 1.str_replace:正则作用:高效快速匹配 2.break ...
- PHP过滤常用标签的正则表达式
$str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...
随机推荐
- Hive 本地调试方法
关键词:hive, debug 本地调试(local debug) Hive 可分为 exec (hive-exec,主要对应源码里的ql目录) 和 metastore 两部分,其中exec对外有两种 ...
- java爬虫案例学习
最近几天很无聊,学习了一下java的爬虫,写一些自己在做这个案例的过程中遇到的问题和一些体会1.学习目标 练习爬取京东的数据,图片+价格+标题等等 2.学习过程 1·开发工具 ...
- Dubbo+zookeeper构建高可用分布式集群(二)-集群部署
在Dubbo+zookeeper构建高可用分布式集群(一)-单机部署中我们讲了如何单机部署.但没有将如何配置微服务.下面分别介绍单机与集群微服务如何配置注册中心. Zookeeper单机配置:方式一. ...
- [Swift]LeetCode330. 按要求补齐数组 | Patching Array
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such th ...
- [Swift]LeetCode498. 对角线遍历 | Diagonal Traverse
Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal ...
- [Swift]LeetCode654. 最大二叉树 | Maximum Binary Tree
Given an integer array with no duplicates. A maximum tree building on this array is defined as follo ...
- [Swift]LeetCode769. 最多能完成排序的块 | Max Chunks To Make Sorted
Given an array arr that is a permutation of [0, 1, ..., arr.length - 1], we split the array into som ...
- [Swift]LeetCode993. 二叉树的堂兄弟节点 | Cousins in Binary Tree
In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1. T ...
- PHP算法之冒泡排序
//冒泡排序 //①思路,先比较出第一次,找一个最大的值,排到最后; //②重复count遍之后,就能得到排序; //③优化,每一次循环之后不需要再次全部重复; $array = [11,5,4,58 ...
- Python中面向对象的概念(科普)
面向对象(OOP)基本概念 面向对象编程 —— Object Oriented Programming 简写 OOP 目标 了解 面向对象 基本概念 01. 面向对象基本概念 我们之前学习的编程方式就 ...