Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

RegExp.prototype.toString()

概述

toString() 返回一个表示该正则表达式的字符串。

语法

regexObj.toString()

参数

描述

RegExp 对象覆盖了 Object 对象的 toString() 方法,并没有继承 Object.prototype.toString()。对于 RegExp 对象,toString 方法返回一个该正则表达式的字符串形式。

示例

例子:使用 toString

下例输出 RegExp 对象的字符串值:

myExp = new RegExp("a+b+c");
alert(myExp.toString());       // 显示 "/a+b+c/"

foo = new RegExp("bar", "g");
alert(foo.toString());         // 显示 "/bar/g"

规范

Specification Status Comment
ECMAScript 3rd Edition. Implemented in JavaScript 1.1 Standard Initial definition.
ECMAScript 5.1 (ECMA-262)
RegExp.prototype.toString
Standard  
ECMAScript 6 (ECMA-262)
RegExp.prototype.toString
Release Candidate  

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

相关链接

文档标签和贡献者

 此页面的贡献者: teoli, AlexChao
 最后编辑者: teoli,