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)。

  • 相关阅读:
    cvxpy 示例代码
    Cora 数据集介绍
    图嵌入
    数学建模
    邮件服务器搭建
    windows安装、使用MongoDB
    Django 特殊查询
    软件测试-软件质量
    软件测试-配置管理(7)
    软件测试-缺陷管理(6)
  • 原文地址:https://www.cnblogs.com/sunzhenxing19860608/p/5190764.html
Copyright © 2011-2022 走看看