RegExp.prototype.toString()

概述

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

语法

regexObj.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 2015 (6th Edition, ECMA-262)
RegExp.prototype.toString
Standard  

浏览器兼容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
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)

相关链接