码迷,mamicode.com
首页 > 编程语言 > 详细

javascript 定义正则表达式

时间:2016-02-15 18:07:22      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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 \n or \r), 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)。

javascript 定义正则表达式

标签:

原文地址:http://www.cnblogs.com/sunzhenxing19860608/p/5190764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!