zoukankan      html  css  js  c++  java
  • js常用的正则表达操作

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script>
                  var past=/helloword/gi;
                  var str='helloword my HelloWord baby';
                  console.log(past.test(str));//返回true or false
    
                  console.log(past.exec(/aa/));//返回匹配到的字符串及其位置 匹配不到返回null
                  console.log(past.exec(str));//返回匹配到的字符串及其位置 匹配不到返回null
                  console.log(str.match(past));//返回匹配到的字符串        匹配不到返回null
                  console.log(str.match(/aa/));//返回匹配到的字符串        匹配不到返回null
                  console.log(str.search(/1/));//返回匹配到的字符串位置     匹配不到返回-1
                  console.log(str.replace(past,"你好"));//字符串替换
                  console.log(str.split(' '));//字符串拆分成数组
                  console.log(str.split(/s+/));//s+匹配空字符串
        </script>
    </head>
    <body>
    
    </body>
    </html>
  • 相关阅读:
    memory addresses
    ddt ddl dml
    PHP Architecture
    disk_free_space
    SAPI
    Simple Mail Transfer Protocol
    AllowOverride None
    function &w(){}
    The History of Operating Systems
    are not called implicitly
  • 原文地址:https://www.cnblogs.com/wujindong/p/6265575.html
Copyright © 2011-2022 走看看