zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然 JAVASCRIPT开发学习:RegExp 对象

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    var str = "Visit RUnoob";
    var patt1 = /runoob/i;
    document.write(str.match(patt1));
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    var str="Is this all there is?";
    var patt1=/is/g;
    document.write(str.match(patt1));
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    var str="Is this all there is?";
    var patt1=/is/gi;
    document.write(str.match(patt1));
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    var patt1=new RegExp("e");
    document.write(patt1.test("The best things in life are free"));
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    var str = 'runoob';
    var patt1 = new RegExp('\w', 'g'); // 有转义作为正则表达式处理
    var patt2 = new RegExp('w', 'g');  // 无转义作为字符串处理
    var patt3 =/w+/g;  // 与 patt1 效果相同
    document.write(patt1.test(str)) //输出 true
    document.write("<br>") 
    document.write(patt2.test(str)) //输出 false
    document.write("<br>") 
    document.write(patt3.test(str)) //输出 true
    </script>
    
    </body>
    </html>

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    </head>
    <body>
    
    <script>
    var patt1=new RegExp("e");
    document.write(patt1.exec("The best things in life are free"));
    </script>
    
    </body>
    </html>

  • 相关阅读:
    bugku-web40
    buuctf-BabyUpload
    webpack4系列之 【1. webpack入门】
    webpack Cannot find module 'webpack/schemas/WebpackOptions.json'
    .gitignore无效解决方案以及git rm和rm的区别
    nginx启动或者重启失败,报错nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
    vue-学习系列之vue双向绑定原理
    mac环境下配置nginx
    杂记
    更换淘宝源
  • 原文地址:https://www.cnblogs.com/tszr/p/10944856.html
Copyright © 2011-2022 走看看