zoukankan      html  css  js  c++  java
  • JavaScript系列:正则表达式

     1 function testExecResultType() {
     2             var txt = "mom and dad and baby";
     3             var pattern = /mom (and day (and baby)?)?/ig;
     4             var match = pattern.exec(txt);
     5             document.writeln("<br>match's type is instanceof array:" + (match instanceof Array));
     6             document.writeln("<br>Array.isArray(matches):" + Array.isArray(match));
     7         }
     8 
     9         function testTelNum() {
    10             var p1 = /^1d{10}$/g;
    11             var pattern = new RegExp(p1.source, "g");
    12             var telNum1 = "13088888888";
    13             var telNum2 = "13300008888";
    14             document.writeln("<br>" + telNum1 + " is telNum:" + pattern.test(telNum1));
    15             pattern.lastIndex = 0;
    16             document.writeln("<br>" + telNum2 + " is telNum:" + pattern.test(telNum2));
    17         }
    18 
    19         function testIfIsPatternObjectIsGlobal() {
    20             var p = /w+@w+.com/g;
    21             var mail = "zhangsan@amail.com";
    22             document.writeln("<br>" + mail + " is mail?" + p.test(mail));
    23             document.writeln("<br>lastIndex: " + p.lastIndex);
    24             p = /^1d{10}/g;
    25             document.writeln("<br>lastIndex: " + p.lastIndex);
    26             var telNum = "13088888888";
    27             document.writeln("<br>" + telNum +" is telNum? " + p.test(telNum));            
    28         }
    29         testIfIsPatternObjectIsGlobal();
    30         //testTelNum();
    31         //testExecResultType();
  • 相关阅读:
    Dropplets – 极简的 Markdown 博客平台
    T3
    Awesomplete
    SVG Drawing Animation
    Dom Animator – 提供 Dom 注释动画的 JS 库
    Electron
    很赞的效果!互动的页面元素拖放着色实验
    BookBlock
    雷军投资的理财网站,年化收益13%!
    Rainyday.js – 使用 JavaScript 实现雨滴效果
  • 原文地址:https://www.cnblogs.com/strinkbug/p/5301333.html
Copyright © 2011-2022 走看看