js进阶正则表达式5几个小实例(原样匹配的字符在正则中原样输出)(取反^

一、总结

原样匹配的字符在正则中原样输出:var reg4=/第[1-2][0-9]章/g //10-29

取反^:var reg1=/[^0-9]/g

二、js进阶正则表达式5几个小实例

 <!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>课堂演示</title>
<style type="text/css">
li{
font-size: 20px;
width: 500px;
background: rgba(0,180,80,0.3);
padding: 10px;
margin: 10px;
}
</style>
</head>
<body>
<script type="text/javascript">
var str1="555aa421html3kk98css44bb52js31hh328cc7213";
var str2="aay我ra12b要b78bc自hcc23a学ab51ck网aambcc";
var str3="第1章 第13章 第21章 第7章 第15章 第51章 第10章..."
var reg1=/[^0-9]/g
var reg2=/[abc]/g
var reg3=/[a-z0-9]/gi
var reg4=/第[1-2][0-9]章/g //10-29
document.write('<ol>')
document.write('<li>'+str1+'<br>'+str2)
document.write('<li>'+str1.replace(reg1,''))
document.write('<li>'+str1.replace(reg2,''))
document.write('<li>'+str2.replace(reg3,''))
document.write('<li>'+str3.match(reg4)) //以数组的形式返回符合条件的数据
document.write('<li>'+str3.match(reg4).length)
document.write('<li>'+str3.match(reg4)[1])
document.write('</ol>') </script>
</body>
</html>

随机推荐

  1. UML中的用例图

    用例图构成:參与者(actor).用例(use case).子系统(subsystem) 关联(Association) 泛化(Inheritance) 就是通常理解的继承关系,子用例和父用例类似,但 ...

  2. java / C++ B+树代码

    C++ 代码 #include <> JAVA 代码 package org.test.me.struct; /** * author: shuly * create: 2018-09-1 ...

  3. WINDOWS8.1企业版官方下载

    这是评估版 WINDOWS8.1企业版官方下载源 https://www.itechtics.com/download-windows-8-1-enterprise-offline-installer ...

  4. matlab 构建数据集实用 api

    我们当前有如下目录结构的图像数据集(用于图像分类): 1. imageDatastore imageDatastore:imds = imageDatastore('./images', 'Inclu ...

  5. Mahout应用

    不多说,直接上干货! Mahout作为Apache基金会的顶级项目之一,Mahout的应用也极其广泛,一般分为商业应用和学术应用. 在商业应用中,Adobe AMP公司使用Mahout的聚类算法把用户 ...

  6. 3. CONFIGURATION官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 3. CONFIGURATION 3.1 Broker Configs 3.2 Pr ...

  7. arm-linux-gcc 命令未找到问题

    解决方法: 1.先打开一个超级用户权限的shell: 命令: ubuntu :sudo –s centos :su - 2.在当前shell下,设置环境变量: 命令:gedit /etc/profil ...

  8. JS 原型模式创建对象

    例子: class Test { constructor(val) { this.val = val } walk() { console.log(this) console.log('walk') ...

  9. eclipse中导入zico Maven项目

    zico源代码地址:https://github.com/jitlogic/zico 简单的说,git上同步的源代码需要先进行maven编译,然后导入eclipse. 如果没有配置好maven,请参考 ...

  10. 需求:在浏览器加载完毕后,自动播放视频:出现play() failed because the user didn't interact with the document first.错误

    解决方法:给video标签加入<video muted></video> 静音即可. Chrome 66为了避免标签产生随机噪音. 参考链接:https://juejin.im ...