zoukankan      html  css  js  c++  java
  • javascript 定义正则表达式

    js中定义正则表达式有两种,使用RegExp和使用字面量。

    使用字面量定义时需要注意:必须以/开始,以/结束,就像定义字符串一样("test")。

    但是,js的正则表达式可以通过指定flag控制匹配的规则,如下所示:

    g
    global match
    i
    ignore case
    m
    multiline; treat beginning and end characters (^ and $) as working over multiple lines (i.e., match the beginning or end of each line (delimited by 
     or 
    ), not only the very beginning or end of the whole input string)
    u
    unicode; treat pattern as a sequence of unicode code points
    y
    sticky; matches only from the index indicated by the lastIndex property of this regular expression in the target string (and does not attempt to match from any later indexes).

    如果指定匹配规则的话,使用字面量定义正则表达式满足:

    1.以/开始

    2.最后一个/之后必须是g、i、m、u、y中的一个(可以同时指定多个flag)。

  • 相关阅读:
    2018常用DOM操作总结
    emlog实现全站pjax无刷新加载页面
    深入理解Vuex 框架
    2018前端最火的web UI框架
    小程序快递单号查询
    表单元素系列二
    表单元素系列一
    表单提交
    AJAX 回调函数刷新页面问题
    electron 常用命令
  • 原文地址:https://www.cnblogs.com/sunzhenxing19860608/p/5190764.html
Copyright © 2011-2022 走看看