zoukankan      html  css  js  c++  java
  • 代码-JS之使用正则对象的成员

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
    
    <script>
        /********* 使用正则对象的成员方式一 *********/
        var str1 = "php phhp";
        var r1 = /ph+p/;
        var result1 = r1.exec(str1);
        console.log(result1);
    
        /********* 使用正则对象的成员方式二 *********/
        //var r = new RegExp(正则表达式[//写法],  修饰符[字符串类型]);
        var str2 = "phP Phhhp";
        var r2 = new RegExp(/ph+p/, 'i');
        var result2 = r2.exec(str2);
        console.log(result2);
    
        /********* 使用正则对象的成员方式三 *********/
        //var r = new RegExp(正则表达式[字符串类型],  修饰符[字符串类型]);
        var str3 = "php phhp phhhp";
        var r3 = new RegExp('(p)h+\1', 'g');
        var result3 = r3.exec(str3);
        console.log(result3);
    </script>
    
    
    </body>
    </html>
    
    Copyright [2018] by [羊驼可以吃吗] form [https://www.cnblogs.com/phpisfirst/]
  • 相关阅读:
    电力三维基础信息平台
    基于三维GIS技术的输电线路地理信息系统的设计与实现
    linux学习笔记(1)
    linux学习笔记(4)
    linux学习笔记(8)
    linux学习笔记(6)
    linux学习笔记(3)
    linux 学习笔记(2)
    linux学习笔记(7)
    ASCII码表完整版
  • 原文地址:https://www.cnblogs.com/phpisfirst/p/9819136.html
Copyright © 2011-2022 走看看