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>

  • 相关阅读:
    div错位解决IE6、IE7、IE8样式不兼容问题
    DIV背景半透明文字不半透明的样式
    Div 自适应屏幕大小
    mysql 设置外键 四大属性 CASCADE SET NULL NO ACTION RESTRICT 理解
    msyql 主从配置
    全国最新区划数据-四级-省-市-县(区)-乡(镇)
    ThinkPHP3.2 伪静态配置
    色彩网站
    Javascript php 异常捕获
    jQuery 操作大全
  • 原文地址:https://www.cnblogs.com/tszr/p/10944856.html
Copyright © 2011-2022 走看看