zoukankan      html  css  js  c++  java
  • js正则常用方法

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>W3Cschool教程(w3cschool.cn)</title>
    </head>
    <body>
    <h1>我的第一个 Web 页面</h1>
    <button id = "demo">clock me</button>
    <script>
    document.getElementById("demo").addEventListener("click",myfun);
    function myfun(){
    //JavaScript 正则表达式
    //定义:正则表达式是由一个字符序列形成的搜索模式
    //语法:pattern/modifiers

    //test方法
    var a = new RegExp("mike");
    document.write(a.test("mike is the best"));

    //exec方法
    var b = new RegExp("love");
    document.write(b.exec("mike have love a girl some years ago"));

    //compile方法
    //replace方法
    var c="her name is lina";
    patt=/(li)?na/g;
    patt.compile(patt);
    document.write(c.replace(patt,"nana"));

    //search方法
    var d = "i wish lina has a happy life everyday";
    document.write(d.search("lina"));

    }

    </script>

    </body>
    </html>

  • 相关阅读:
    字符串练习
    python基础
    熟悉常用的Linux操作
    大数据概述
    递归下降分析程序
    自动机
    词法语法分析1
    关于我对编译原理的理解
    6小时学会TypeScript入门实战教程(大地)
    kotlin
  • 原文地址:https://www.cnblogs.com/mike1314/p/8012753.html
Copyright © 2011-2022 走看看