---
title: "正则再了解——test方法"
author: "sailinglee"
date: "2014-06-19T09:16:29Z"
tags: []
categories: ["Web前端"]
slug: "test"
draft: false
lastmod: "2014-06-19T09:16:29Z"
id: 2082387
url: "https://sailinglee.iteye.com/blog/2082387"
---

不经意发现正则的test方法也会产生捕获结果。

```
/(\w)(\w)/.test("acbd");
alert(RegExp.$1);//a
alert(RegExp.$2);//c


倘若这样写：
/(?:\w)(\w)/.test("acbd");
alert(RegExp.$1);//c
alert(RegExp.$2);//"",ie可能为undefined


这就不难解释为什么在使用test方法时也使用非捕获的的标识：?:
```