• jsRegExp对象


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript">
    //正则对象
    //1 构造方法
    //参数1 正则字符串 ,参数2 匹配模式
    //用户名必须 以字母开头,长度在6到10位之间.
    //匹配模式有两种
    //"i": 忽略大小写. ignoredCase
    //"g": 全局匹配 global
    var reg1 = new RegExp("^[a-zA-Z][a-zA-Z_0-9]{5,9}$","g");
    var reg2 = /^[a-zA-Z][a-zA-Z_0-9]{5,9}$/g;
    //2 方法
    //test方法 ==> 测试字符串与正则是否匹配.
    var username = "a3456";
    //alert(reg1.test(username));//true

    //与String对象结合的4个方法
    var str = "hello world";
    //split 切割字符串
    //alert(str.split(/o/g));
    //replace 查找替换
    //alert(str.replace(/o/g, "haha"));
    //search 只能找第一个出现的位置. 如果需要查找第n个出现的位置使用exec方法.
    //alert(str.search(/o/g));
    //match ==> 找到字符串中符合正则表达式的部分并返回.
    alert(str.match(/o/g));
    </script>
    </head>
    <body>
    </body>
    </html>

  • 相关阅读:
    Docker宿主机管理
    Docker常用命令
    Maven专题4——Maven测试
    Spring Boot 2.x 之 Logging
    spark高可用集群搭建立
    elastic插件安装
    单实例安装elastic和启动报错解决
    使用Turbine对集群进行监控
    Centos安装mysql5.6.33
    Centos6安装破解JIRA7.3.8
  • 原文地址:https://www.cnblogs.com/nextgg/p/7646640.html
Copyright © 2020-2023  润新知