Home > Web Front-end > JS Tutorial > body text

调试JavaScript中正则表达式中遇到的问题_javascript技巧

WBOY
Release: 2016-05-16 16:17:40
Original
1133 people have browsed it

关于正则表达式中字符串测试分问题,我们一般有test()和exec()两种方法,关于这两种方法的区别我这里就不加详细阐述了,主要就是test()返回布尔值,exec()返回匹配到的字符数组,但是今天我遇到一个问题, 程序非常简单,但是里面的问题让我很想不通,在网上找答案也没有找到(个人比较菜)。

复制代码 代码如下:

var pattern=new RegExp("match","ig");
alert(pattern.test("Match"));
alert(pattern.exec("Match"));

  第一个alert()的值在预料之中为true

但是第二个测试值却出人意料的为null

关于这个问题我不知道是什么原理,因为我没看到函数源码,如果有朋友能够指出感激不尽!!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!